All About ASP.NET and ASP.NET Core 2 Hosting BLOG

Tutorial and Articles about ASP.NET and the latest ASP.NET Core

ASP.NET 4.5.1- with ASPHostPortal.com :: How to Create Barcodes using ASP.NET App

clock February 26, 2014 05:09 by author Kenny

To create barcodes we will use ASP.NET web services. Not only that, we will also create Windows Forms and Console application to request barcode image.

What is The Benefits?

Well, web services provide a major benefit in integrating the software with external applications. With standardized request/response model, any client application that can utilize XML web service can benefit from it.Below is the brief visual representation of the barcode service. The clients do not need to refer to Aspose.BarCode for .NET. They will just send 2 string values (codetext and symbology) and will get the barcode image (byte array) from service.

Barcode Web Service
Now, open Microsoft Visual Studio. Create a new project of type “ASP.NET Web Service Application”. Name the project as “BarCodeService”. Add reference to the following .NET assemblies.

  1. System.Drawing from .NET tab of “Add Reference” dialog box
  2. Aspose.BarCode.

Browse to the location where Aspose.BarCode for .NET is installed and select. Visual Studio adds a default class “Service1” to the Web Service project in Service1.asmx file.
Open it and add the following method to this class.

The web method needs the following two parameters from client:

  1. Codetext
  2. Symbology

These parameters are of String type. The parameters are passed to the BarCodeBuilder class, which then creates the barcode and sends the barcode image in the form of byte array to the client.
This web method can be called by any kind of application that can consume a web service.


Consume Web Service from Windows Forms Application

Open Visual Studio and create a new project of type “Windows Application”. Name the project as “ GetBarCodeWinForms ”. Add reference to the web service by right clicking on “References” and then choosing “Add Service Reference” from the context menu. Type the address of web service or discover it. After getting the correct service, give “BarCodeService” in the Namespace and click on “Ok” button to add the reference.

Design the forms as follows.

It contains the following controls:

  1. Textbox: Input codetext from user
  2. Combobox: Input symbology type from user
  3. Button: Call web service
  4. Picturebox: Display the barcode image

Write the following code on click event of the button.

Run the application, specify some values and click on the “Get Barcode” button. The application will consume the barcode web service and get the barcode image from it. The image will then be displayed on the form as below.

Consume Web Service from a Console Application

Create a new project in Visual Studio and choose “Console Application” in project type. Name the project as “ GetBarCodeConsole ”. Add the reference to the barcode service, just as we gave above in the winforms application.Write the below code in the main() method.

Run the application, it will consume the barcode web service, get barcode image and save the image locally to disk.

Summary

Aspose.BarCode for .NET can easily be used in ASP.NET web services to generate the barcodes and serve the barcode image to various clients.



ASP.NET 4.5.1 with ASPHostPortal.com :: An Overview on the Advance ASP.NET 4.5.1 Technology

clock February 24, 2014 10:34 by author Kenny

What's the new from ASP.NET?  Noting that the 32-bit edit & continue was released in 2005,  that the 64-bit equivalent is part of ASP.NET 4.5.1.  The functionality is exactly the same as in the 32-bit version.Next, but it has the new ability to inspect method return values.  This can be done in the Visual Studio’s “Autos” window or in the immediate window.

 

The return value can be expanded in the debugger so that the current value can be viewed.  The debugging of asynchronous code is made easier with improvements to the usability of the Call Stack and Tasks Window for apps targeting the Windows Store, Web Apps, and Windows 8.1 Desktop Apps.That isn’t the only improvement for Windows Store apps, as now developers can convert Convert System.IO.Stream to IRandomAccessStream.  Enhancements have also been made to WinRT’s type system (through introduction of nullable value types)  and better exception support (example: System.Exception.Message, System.Exception.StackTrace).  

These new System.Exception properties improve over the Windows 8 experience since previously an attached debugger was necessary to avoid losing information. Whereas previously a broken network connection would lead to exceptions, the new 4.5.1 experience will handle the failure gracefully.  Should the network connection become repaired, the application will identify this and continue working.ASP.NET applications can now be suspended transparently.  The actual ASP.NET worker process is suspended in a ready to go state, with a 90% reduction in startup time.  Once the application has been idle for awhile, it is paged to disk, and then retrieved when a request for the app comes in and/or is made. This functionality can be enabled via IIS Settings by changing Idle Time-out Action to “Suspend”.Under the hood, in .NET 4.5.1, you can now compact the Large Object Heap (LOH) to address heap fragmentation.  

The LOH mode is part of GCSettings, but Heydarian cautions that “with great power comes great responsibility” and that this should never have be used in ordinary development.Improvements have been made to multicore Just-In-Time (JIT) performance, Heydarian stating a 15% performance improvement for cold startups.Another area improved in .NET 4.5.1 is around the behavior of the system after the framework has been updated.  Today servicing the .NET Framework can lead to degradation in app performance directly afterwards.  This is due to core .NET assemblies being JIT-compiled for a period of time after being updated/patched.  In Windows 8.1 app performance remains consistent even after servicing the .NET Framework.  This results in a much better user experience and supports Microsoft’s efforts to provide better battery life on tablets wherever possible.One of the goals Heydarian stated his team has is to do all of the heavy lifting so that the .NET developers all benefit.  Second, he whenever possible he wants the platform’s improvements to benefit developers with minimal (if any) recoding—just better performance.



ASP.NET 4.5.1 Hosting with ASPHostPortal.com :: Configuring BotDetect ASP.NET CAPTCHA Options

clock February 18, 2014 06:08 by author Ben

1. BotDetect CAPTCHA ASP.NET Configuration

BotDetect Captcha properties can be set in several different ways, depending on the type of value you are customizing.

2. BotDetect CAPTCHA Web.Config Configuration Section

BotDetect configuration options which apply to all Captcha instances within a particular ASP.NET application can be specified in the web.config file. This approach can be seen in the Captcha customization code sample coming with the BotDetect installation.

This configuration section first needs to be registered at the top of the web.config file:

<configuration>

  <configSections>

    <!-- Register the BotDetect configuration section -->

    <section name="botDetect" requirePermission="false"

      type="BotDetect.Configuration.BotDetectConfigurationSection,

        BotDetect" />

  </configSections>

 

 

You can then create the <botDetect> section just below the closing </configSections> element, and (for example) disable all audio Captcha sounds in the application by specifying:

<botDetect>

  <captchaSound enabled="false" />

</botDetect>

3. BotDetect CAPTCHA .aspx / Visual Studio Designer Instance Settings

When adding the BotDetect:Captcha control to the .aspx file defining your form (either by using the Visual Studio Designer or editing the source directly), you can specify various attributes in the element declaration. For example, the simplest way to specify Captcha image size is:

<BotDetect:Captcha ID="SampleCaptcha" runat="server" ImageSize="200, 50" />

However, it's not recommended to use this method to set all Captcha instance properties. Page source declarations are processed when the page is loaded, and since they have to be applied to Captcha images and sounds (which come as separate Http requests), they have to be saved in ASP.NET Session state. It's better not to take up Session space if it's not necessary.

4. BotDetect CAPTCHA Code-Behind Instance Settings

It's also possible to specify various Captcha object settings in your page code-behind code. For example, code type and length can be set in the Page_PreRender override:

protected void Page_PreRender(object sender, EventArgs e)

{

  // initial page setup

  if (!IsPostBack)

  {

    // Captcha code properties

    SampleCaptcha.CodeLength = 4;

    SampleCaptcha.CodeType = BotDetect.CodeType.Numeric;

}

The same caveat applies to this method as with .aspx settings: this code is executed when the form is loaded, but since Captcha images and sounds are loaded in separate Http requests (which don't result in this code being executed), all values set this way have to be saved in ASP.NET Session state. Since different visitors will use separate Sessions, the amount of state used is multiplied by the number of active visitors / Sessions, and it's better not to use a lot of it.

5. BotDetect CAPTCHA Event Handler Property Setting and Randomization

This is the recommended approach to Captcha instance property setting. It's the most complex method, since it requires setting up an event handler. But since this handler is going to be executed for all Captcha requests (including separate Captcha image and sound Http requests), there is no need to persist the values in ASP.NET Session state.

Randomizing Captcha properties significantly improves Captcha security, and it should always be performed in this event handler instead of Page_Load or Page_PreRender, because the Captcha control event is also fired for direct Captcha image and sound requests (which skip the page events since the page is never loaded) – for example when clicking the Captcha reload button repeatedly.

You can see this approach to BotDetect Captcha property setting implemented in the Captcha randomization code sample coming with the BotDetect installation.

First, a InitializedCaptchaControl event handler needs to be registered in the Page_Init override:

protected void Page_Init(object sender, EventArgs e)

{

  SampleCaptcha.InitializedCaptchaControl +=

    new EventHandler<InitializedCaptchaControlEventArgs>(

      SampleCaptcha_InitializedCaptchaControl);

}

Then, randomization rules can be declared in the event handler:

void SampleCaptcha_InitializedCaptchaControl(object sender,

  InitializedCaptchaControlEventArgs e)

{

  if (e.CaptchaId != SampleCaptcha.CaptchaId)

  {

    return;

  }

  CaptchaControl captcha = sender as CaptchaControl;

  // randomize code generation properties

  captcha.CodeStyle = CaptchaRandomization.GetRandomCodeStyle();

  captcha.CodeLength = CaptchaRandomization.GetRandomCodeLength(4, 5);

  captcha.ImageStyle = CaptchaRandomization.GetRandomImageStyle();

  captcha.SoundStyle = CaptchaRandomization.GetRandomSoundStyle();

}

The CaptchaRandomization helper allows easy randomization of Captcha parameters.

 



ASP.NET MVC 5.1 Hosting :: ASPHostPortal.com Proudly Launches ASP.NET MVC 5.1 Hosting

clock January 28, 2014 07:48 by author Ben

ASPHostPortal.com officially launches ASP.NET MVC 5.1  hosting at affordable prices. Instant Setup, Fast and Friendly Support!

ASPHostPortal.com, a leading innovator in Windows Hosting, announces the launch of ASP.NET MVC 5.1 Hosting. The ASP.NET MVC 5.1 Framework is the latest evolution of Microsoft’s ASP.NET web platform. It provides a high-productivity programming model that promotes cleaner code architecture, test-driven development, and powerful extensibility, combined with all the benefits of ASP.NET.

ASP.NET MVC 5.1 contains a number of advances over previous versions, including the ability to define routes using C# attributes and the ability to override filters,Enum support in Views, Support for current Context in Unobtrusive Ajax, Filter Overrides and etc. The user experience of building MVC applications has also been substantially improved.

The company believes in providing top-notch service at affordable price. They offer ASP.NET MVC 5.1 hosting with the following features such as Unlimited Domain, Unlimited Subdomain, 5 GB Disk Space, 2 SQL Database and Unlimited Email Account.
 
“Our customers have been asking us about MVC 5.1 and we are happy to deliver a hosting platform that supports all the latest in the Microsoft Web Stack.” said said Dean Thomas, Manager at ASPHostPortal.com.  "And it proves that we remain at the forefront in Microsoft technology".

Where to look for the best ASP.NET MVC 5.1 hosting service? How to know more about the different types of hosting services? Read more about it on http://www.asphostportal.com.


About ASPHostPortal.com:

ASPHostPortal.com is a hosting company that best support in Windows and ASP.NET-based hosting. Services include shared hosting, reseller hosting, and sharepoint hosting, with specialty in ASP.NET, SQL Server, and architecting highly scalable solutions. As a leading small to mid-sized business web hosting provider, ASPHostPortal.com strive to offer the most technologically advanced hosting solutions available to all customers across the world. Security, reliability, and performance are at the core of hosting operations to ensure each site and/or application hosted is highly secured and performs at optimum level.



ASP.NET 4.5.1 Hosting - ASPHostPortal.com :: How to Create a Sign Up/Registration Page in ASP.NET

clock January 10, 2014 07:17 by author Ben

Here is the simple step to create a sign up/registration page in ASP.NET. Lets check this out :
1. Open the Microsoft Visual Studio
2. Select one New Asp.Net Web application
3. Open the Design Default.aspx page
4. Drag and Drop one DropDown list and button from the Tool box.
5. Add one new item( i.e., New Registration Page) for the Drop down list
6. Procedure for adding items : Right click on the DropDown List and select properties and select items and add NewRegistration in Text Field.
7. Change the properties of the Dropdown list
a.Kept AutopostBack = True;
b.select the SelectedIndexChanged Event for that..
8. Open the code page that is Default.aspx.cs and and create a method in SelectedIndexChanged event of dropdownlist

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using System.Data.SqlClient; 
 
public partial class Dynamic_controls : System.Web.UI.Page 

    SqlConnection con; 
    SqlCommand com; 
  protected void Page_Load(object sender, EventArgs e) 
    {        
        
    } 
protected void ddlist_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        Createnewaccount();  
    } 

9. Create new methods for Different controls by using the main method(i.e., Createnewaccount)

private void Createnewaccount ()
         {
             CreateDynamicTextBoxes ();
             CreateDynamicTextBoxes1 ();
             CreateDynamicCheckBoxes ();
             CreateDynamicCheckBoxes1 ();
             CreateDynamicRadioButtons1 ();
             BindDropDownLists ();
         }

10. Create all types of dynamic controls

 protected void CreateDynamicTextBoxes ( )
        {
           
            int c = 1 ;
            TextBox [ ] textBoxArr = new TextBox [ c ] ;/ / array of textboxes
            for (int i = 0 ; i < c ; i + + )
            {
                 
                textBoxArr [ i ] = new TextBox ( ) ;
                textBoxArr [ i ] . ID = " txtBox " + i.ToString ( ) ;
                PH_Name.Controls.Add ( textBoxArr [ i ] ) ;
                RequiredFieldValidator reqfldVal = new RequiredFieldValidator ( ) ;
                reqfldVal.ID = " RequiredValidator " + i ;
                reqfldVal.ControlToValidate = " txtBox " + i ;
                reqfldVal.ErrorMessage = " Not Empty " ;
                reqfldVal.SetFocusOnError = true ;
                PH_Name.Controls.Add ( reqfldVal ) ;
            }
        }
        protected void CreateDynamicTextBoxes1 ( )
        {
            int c = 1 ;
            TextBox [ ] textBoxArr1 = new TextBox [ c ] ;/ / array of textboxes
            for (int i = 0 ; i < c ; i + + )
            {
      
                textBoxArr1 [ i ] = new TextBox ( ) ;
                textBoxArr1 [ i ] . ID = " txtBox1 " + i.ToString ( ) ;
                PH_pwd.Controls.Add ( textBoxArr1 [ i ] ) ;
                RequiredFieldValidator reqfldVal1 = new RequiredFieldValidator ( ) ;
                reqfldVal1.ID = " RequiredValidator1 " + i ;
                reqfldVal1.ControlToValidate = " txtBox1 " + i ;
                reqfldVal1.ErrorMessage = " Not Empty " ;
                reqfldVal1.SetFocusOnError = true ;
                PH_pwd.Controls.Add ( reqfldVal1 ) ;
                 
            }
        }
        private void BindDropDownLists ( )
        {
            SqlDataSource sqlDS = new SqlDataSource ( ) ;
            sqlDS.ConnectionString = ConfigurationManager.ConnectionStrings [ " SAMPLE_2 " ] . ToString ( ) ;
            sqlDS.SelectCommand = " Select CountryID , COUNTRY_NAME from countrynames " ;
            PH_country.Controls.Add ( sqlDS ) ;
            DropDownList ddl = new DropDownList ( ) ;
            ddl.ID = " ddlrank " ;
            ddl.DataSource = sqlDS ;
            ddl.DataTextField = " COUNTRY_NAME " ;
            ddl.DataValueField = " CountryID " ;
            PH_country.Controls.Add ( ddI ) ;
            foreach ( Control ctl in PH_country.Controls )
            {
                if ( ctl is DropDownList )
                {
                    ( ctl as DropDownList ) . DataBind ( ) ;
                }
            }
        }
        protected void CreateDynamicCheckBoxes ( )
        {
                   
                CheckBox chk ;
                chk = new CheckBox ( ) ;
                chk.ID = " chkhobbies " ;
                chk.Text = " savings " ;
                chk.AutoPostBack = false ;
                PH_trans.Controls.Add ( chk ) ;
             
        }
        protected void CreateDynamicCheckBoxes1 ( )
        {
           
            int c = 1 ;
            CheckBox [ ] chk = new CheckBox [ c ] ;
            for (int i = 0 ; i < c ; i + + )
            {
                chk [ i ] = new CheckBox ( ) ;
                chk [ i ] . ID = " chkhobbies1 " + i.ToString ( ) ;
                chk [ i ] . Text = " Current" ;
                chk [ i ] . AutoPostBack = false ;
                PH_trans.Controls.Add ( chk [ i ] ) ;
            }
        }
        protected void CreateDynamicRadioButtons ( )
        {
                Male = new RadioButton RadioButton ( ) ;
                Female = new RadioButton RadioButton ( ) ;
                male = new RadioButton ( ) ;
                female = new RadioButton ( ) ;
                male.Text = " Male " ;
                female.Text = " Female " ;
                male.Checked = false ;
                female.Checked = false ;
                male.GroupName = " unknown " ;
                female.GroupName = " unknown " ;
                male.ID = " malegender " ;
                female.ID = " unknown " ;
                male.AutoPostBack = false ;
                female.AutoPostBack = false ;
                PH_gender.Controls.Add ( male ) ;
                PH_gender.Controls.Add (female ) ;
        }
        protected void CreateDynamicRadioButtons1 ( )
        {
            RadioButtonList radio = new RadioButtonList ( ) ;
            radio.ID = " rblRow " ;
            radio.Items.Add ( new ListItem ( " Male " ) ) ;
            radio.Items.Add ( new ListItem ( " Female " ) ) ;
            PH_gender.Controls.Add ( radio ) ;
             
        }
        protected void CreateDynamicPanel ( )
        {
           
            int c = 1 ;
            TextPanel panel = new Panel ( ) ;
            for (int i = 0 ; i < c ; i + + )
            {
                TextPanel.ID = " txtPanel " + i.ToString ( ) ;
                PlaceHolder1.Controls.Add ( TextPanel ) ;
            }
        }

11. Add the following code to store the data in database

protected void btn_submit_Click ( object sender , EventArgs e )
        {
            for (int i = 0 ; i < 1 ; i + + )
            {
                 
                txtvalue string = " txtBox " + i.ToString ( ) ;
                txtvalue1 string = " txtBox1 " + i.ToString ( ) ;
                ddlvalue string = " ddlrank " ;
                chkvalue string = " chkhobbies " ;
                chkvalue1 string = " chkhobbies1 " + i.ToString ( ) ;
                rbvalue string = " rblRow " ;
                 
                TextBox txt = ( TextBox ) PlaceHolder1.FindControl ( txtvalue ) ;
                TextBox txt1 = ( TextBox ) PlaceHolder1.FindControl ( txtvalue1 ) ;
                DropDownList Dddl = ( DropDownList ) PlaceHolder1.FindControl ( ddlvalue ) ;
                CheckBox Dchk = ( CheckBox ) PlaceHolder1.FindControl ( chkvalue ) ;
                CheckBox Dchk1 = ( CheckBox ) PlaceHolder1.FindControl ( chkvalue1 ) ;
                RadioButtonList Drd = ( RadioButtonList ) PlaceHolder1.FindControl ( rbvalue ) ;
                if ( txt ! = null )
                {
                    try
                    {
                        string strText = txt.Text ;
                        strText1 string = txt1.Text ;
                        strddl string = Dddl.SelectedItem.Text ;
                        strchk string = Dchk.Text ;
                        strchk1 string = Dchk1.Text ;
                        strrdb string = Drd.Text ;
                        / / Store value in database textbox Cell
                        con = new SqlConnection ( ConfigurationManager.ConnectionStrings [ " SAMPLE_2 " ] . ToString ( ) ) ;
                        con.Open ( ) ;
                        com = new SqlCommand ( " insert into Dynamic_Form ( UserName , LastName , DropdownlistValue , Chksavings , Chkcurrent , Radiovalue ) values ​​( ' " + strText + " ' , ' " + strText1 + " ' , ' " + strddl + " ' , ' " strchk + + " ' , ' " + strchk1 + " ' , ' " + strrdb + " ' ) " , con ) ;
                        com.ExecuteNonQuery ( ) ;
                        con.Close ( ) ;
                        lbl_error.Text = " Account Successfully Created " ;
                         
                    }
                    catch ( Exception ex )
                    {
                        throw ex ;
                        / / lbl_error.Text = " There is a problem while creating Account " ;
                         
                    }
                }
            }
        }

Now, run your program and see the result :



ASP.NET MVC 4.0 Hosting with ASPHostPortal :: How To Save Email from External Login in ASP.NET MVC 4.0 with SimpleMembership

clock January 9, 2014 06:16 by author Ben

ASP.NET MVC 4 web application allows users to log in from an external provider, such as Facebook, Twitter, Microsoft or Google and then integrate into your web application. Some OAuth/OpenId providers like Facebook, Google allow to access email. This article explains how to save the email in your database.

Before implementing, first lets consider following points:
1. User name is different from Email.
2. Email might be different for different providers.
3. Email is optional(some external provider like twitter doesn’t allow to access email).

 

Getting Started:
1. Create a new ASP.NET MVC 4 --> Internet Application Project
2. Open App_Start --> AuthConfig.cs, uncomment the external services which you want to use and pass proper parameters. In this article, we will use Facebook,Twitter and Google providers.

OAuthWebSecurity.RegisterTwitterClient(
        consumerKey: "xxxx",
        consumerSecret: "xxxxxxxx");
    OAuthWebSecurity.RegisterFacebookClient(
        appId: "yyyy",
        appSecret: "yyyyyyyy");
    OAuthWebSecurity.RegisterGoogleClient();


3. In Account Model, add Email property in RegisterExternalLoginModel class:

public class RegisterExternalLoginModel
   {
       [Required]
       [Display(Name = "User name")]
       public string UserName { get; set; }
       public string ExternalLoginData { get; set; }
       public string Email { get; set; }
   }

4. To add Email field in OAuthMembership table, add following class:

[Table("webpages_OAuthMembership")]
   public class OAuthMembership
   {
       [Key, Column(Order = 0), StringLength(30)]
       public string Provider { get; set; }
       [Key, Column(Order = 1), StringLength(100)]
       public string ProviderUserId { get; set; }
       public int UserId { get; set; }
       [StringLength(100)]
       public string Email { get; set; }
   }


5. add OAuthMembership in Userscontext

public class UsersContext : DbContext
    {
        public UsersContext()
            : base("DefaultConnection")
        {
        }
        public DbSet<UserProfile> UserProfiles { get; set; }
        public DbSet<OAuthMembership> OAuthMemberships { get; set; }
    }

It will create the required structure in database when you run the application and open register page first time.

Controller Changes:
In AccountController, To set email from the external provider, replace the following lines in ExternalLoginCallback method :

// User is new, ask for their desired membership name
string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName;ViewBag.ReturnUrl = returnUrl;
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = result.UserName, ExternalLoginData = loginData });


with the following lines:

// User is new, ask for their desired membership name
               string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
               ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName;
               ViewBag.ReturnUrl = returnUrl;
               var model = new RegisterExternalLoginModel { UserName = result.UserName, ExternalLoginData = loginData };
               switch (result.Provider) {
                   case "facebook":
                   case "google":
                       {
                           model.Email = result.UserName;
                           model.UserName = "";
                           break;
                       }
                   case "twitter":
                       {
                           model.Email = "";
                           model.UserName = result.UserName;
                           break;
                       }
                   default:
                       break;
               }
               return View("ExternalLoginConfirmation", model);

Facebook and Google provide email as user name, so email is assigned for these providers.

In ExternalLoginConfirmation view, add following Email in form:

@Html.HiddenFor(m => m.Email)

It will post Email also when form is submitted. In ExternalLoginConfirmation method, To save email for new user,replace the following lines:

// Insert name into the profile table
            db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
            db.SaveChanges();
            OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
            OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);
            return RedirectToLocal(returnUrl);

with these lines:

// Insert name into the profile table
                       user = new UserProfile { UserName = model.UserName };
                       db.UserProfiles.Add(user);
                       db.SaveChanges();
                       OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);                                           
                       if (!String.IsNullOrEmpty(model.Email)) {
                           var oauthItem = db.OAuthMemberships.FirstOrDefault(x => x.Provider == provider && x.ProviderUserId == providerUserId && x.UserId == user.UserId);
                           if (oauthItem != null) {
                               oauthItem.Email = model.Email;
                               db.SaveChanges();
                           }
                       }
                       OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);
                       return RedirectToLocal(returnUrl);

This will save email in database for new user. Now if same user wants to add other external provider then in ExternalLoginCallback method, replace following line

OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name);

with following lines:

OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name);
               if (result.Provider == "facebook" || result.Provider == "google")
               {
                   using (UsersContext db = new UsersContext())
                   {
                       UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == User.Identity.Name);                     
                       if (user != null)
                       {                         
                               var oauthItem = db.OAuthMemberships.FirstOrDefault(x => x.Provider == result.Provider && x.ProviderUserId == result.ProviderUserId && x.UserId == user.UserId);
                               if (oauthItem != null)
                               {
                                   oauthItem.Email = result.UserName;
                                   db.SaveChanges();
                               }                         
                       }
                   }
               }

That's the tutorial How To Save Email from External Login in ASP.NET MVC 4.0 with SimpleMembership. If you're looking for best Windows ASP.NET hosting, ASP.NET MVC 4.0 hosting, cloud hosting, and SharePoint hosting, please feel free to visit http://ASPHostPortal.com. Come to the website to know more details.

 



Enterprise Email Hosting :: ASPHostPortal.com Launches Reliable and Scalable Enterprise Email Hosting

clock December 17, 2013 05:04 by author Ben

ASPHostPortal.com, a leading Windows web hosting provider, proudly announces Enterprise Email Hosting for all costumer. With Enterprise Email Hosting Services from ASPHostPortal.com, you’ll find the perfect hosted email solution for your small business. These professional tools and features enable you to access and manage your email and communicate and collaborate from your desktop or mobile devices anywhere in the world.

Enterprise Email Hosting uses the Internet to communicate information about promotions, company offerings, product updates and more. It is a valuable dialogue between a prospective or current customer and a company. Enterprise Email Hosting is more cost effective, and achieves results faster than traditional direct mail marketing. Most importantly, This service is twice as effective as traditional direct mail in getting a response from the targeted audience.

ASPHostPortal.com offer Enterprise Email hosting with the following features:

  • 2 GB Mailbox Space
  • Support Blackberry
  • WebMail Access
  • POP/SMTP/IMAP
  • Total Bulk Email up to 10.000 emails/month


"An  enterprise email hosting account costs $8.00 per month and gives you 10 mailbox that you can access using your smartphone especially Blackberry, Webmail and POP3 Email programs like Outlook.  Once it is ordered it is available to use immediately."said Dean Thomas, Manager at ASPHostPortal.com.

Web hosting is gaining huge amount of popularity because of its several benefits. The most popular hosting of all is Email hosting. A good email hosting has the ability to protect all the important emails.

Where to look for the best email hosting service? How to know more about the different types of hosting services? Read more about it on http://www.asphostportal.com.


About ASPHostPortal.com:


ASPHostPortal.com is a hosting company that best support in Windows and ASP.NET-based hosting. Services include shared hosting, reseller hosting, and sharepoint hosting, with specialty in ASP.NET, SQL Server, and architecting highly scalable solutions. As a leading small to mid-sized business web hosting provider, ASPHostPortal.com strive to offer the most technologically advanced hosting solutions available to all customers across the world. Security, reliability, and performance are at the core of hosting operations to ensure each site and/or application hosted is highly secured and performs at optimum level.



Free ASP.NET 4.5.1 Hosting - ASPHostPortal :: How To Create and Delete Cookies Using ASP.NET

clock December 10, 2013 06:24 by author Ben

Cookies is a small piece of information stored on the client machine. This file is located on client machines "C:\Document and Settings\Currently_Login user\Cookie" path.  Its is used to store user preference information like Username, Password,City and PhoneNo etc on client machines that you created in ASP.NET.
Cookies could be stolen by hackers to gain access to a victim's web account. Even cookies are not software and they cannot be programmed like normal executable applications. Cookies cannot carry viruses and cannot install malware on the host computer. However, they can be used by spyware to track user's browsing activities.

How to create a cookie?
There are many ways to create cookies, I am going to outline some of them below:
Example 1:
HttpCookie userInfo = new HttpCookie("userInfo");
userInfo["UserName"] = "Annathurai";
userInfo["UserColor"] = "Black";
userInfo.Expires.Add(new TimeSpan(0, 1, 0));
Response.Cookies.Add(userInfo);


Example 2:
Response.Cookies["userName"].Value = "Annathurai";
Response.Cookies["userColor"].Value = "Black";


How to delete cookie?
Now look at the code given below which will delete cookies.
Example 1:
string User_Name = string.Empty;
string User_Color = string.Empty;
User_Name = Request.Cookies["userName"].Value;
User_Color = Request.Cookies["userColor"].Value;

Example 2:
string User_name = string.Empty;
string User_color = string.Empty;
HttpCookie reqCookies = Request.Cookies["userInfo"];
if (reqCookies != null)
{
User_name = reqCookies["UserName"].ToString();
User_color = reqCookies["UserColor"].ToString();
}


When we make request from client to web server, the web server process the request and give the lot of information with big pockets  which will have Header information, Metadata, cookies etc., Then repose object can do all the things with browser.

Cookie's common property:

  • Domain => Which is used to associate cookies to domain.
  • Secure  => We can enable secure cookie to set true(HTTPs).
  • Value    => We can manipulate individual cookie.
  • Values  => We can manipulate cookies with key/value pair.
  • Expires => Which is used to set expire date for the cookies.


Advantages of Cookie:

  • Its clear text so user can able to read it.
  • We can store user preference information on the client machine.
  • Its easy way to maintain.
  • Fast accessing.
  • Disadvantages of Cookie
  • If user clear cookie information we can't get it back.
  • No security.
  • Each request will have cookie information with page.


How to clear the cookie information?
we can clear cookie information from client machine on cookie folder

To set expires to cookie object
userInfo.Expires = DateTime.Now.AddHours(1);
It will clear the cookie with one hour duration.


Our Special ASP.NET 4.5.1 Hosting Complete Features

  1. 24/7 Monitoring, We do 24/7 monitoring of your ASP.NET to make sure that we proactively kill any trouble. This helps to ensure maximum uptime and performance.
  2. Easy-to-use service (1-click installs), ASPHostPortal.com gives you access to all SimpleScripts features, provides easy one-click installation and management of all popular applications.
  3. Fast and Secure Server, Our powerfull servers are especially optimized and ensure the best ASP.NET 4.5.1 performance. We have best data centers on three continent and unique account isolation for security.
  4. Daily Backup Service, We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it.



ASP.NET 4.5 Hosting :: Regex (Regular Expressions) Time Out In ASP.NET 4.5

clock November 13, 2013 07:13 by author Ben

One of new features from ASP.NET 4.5 is Regex. Lets start by the new Regex Api introduced with the framework. The improvement that has been made is minor yet handy at certain cases. The Regex class of .NET 4.5 supports Timeout. Lets take a look how to work with it.

Lets try to write a simplest RegEx validator to look into it.



Here in the code you can see I simply check a string with a Regular expression. It eventually finds success as Pattern matches the string. Now this code is little different than what we have been doing for last few years. The constructor overload of Regex now supports a Timespan seed, which indicates the timeout value after which the Regular expression validator would automatically generate a RegexMatchTimeoutException. The Match defined within the Regex class can generate timeout after a certain time exceeds.

You can specify Regex.InfiniteMatchTimeout to specify that the timeout does not occur. The value of InfiniteMatchTimeout is -1ms internally and you can also use Timespan.Frommilliseconds(-1) as value for timespan which will indicate that the Regular expression will never timeout which being the default behavior of our normal Regex class. Regex also supports AppDomain to get default value of the Timeout. You can set timeout value for "REGEX_DEFAULT_MATCH_TIMEOUT" in AppDomain to set it all the way through the Regular expressions being used in the same AppDomain. Lets take a look how it works.



Now this works exactly the same as the previous one. Here the Regex(new feature of ASP.NET 4.5) constructor automatically checks the AppDomain value and applies it as default. If it is not present, it will take -1 as default which is Infinite TImeout and also if explicitely timeout is specified after the default value from AppDomain, the Regex class is smart enough to use the explicitly set value only to itself for which it is specified. The Regex Constructor generates a TypeInitializationException if appdomain value of Timespan is invalid. Lets check the internal structure.



This is the actual code that runs in background and generates the timeouts. Infact while scanning the string with the pattern, there is a call to CheckTimeout which checks whether the time specified is elapsed for the object. The CheckTimeout throws the exception from itself.

The Constructor sets DefaultMatchTimeout when the object is created taking it from AppDomain data elements.

If the pattern is supplied from external or you are not sure about the pattern that needs to be applied to the string, it is always recommended to use Timeouts. Basically you should also specify a rational limit of AppDomain regex default to ensure no regular expression can ever hang your application.

This is a small tip on the new Regex enhancements introduced with .NET 4.5 recently.  I hope you like it. More to come shortly.



Free Trial ASP.NET 4.5.1 Hosting :: ASPHostPortal.com Proudly Launches ASP.NET 4.5.1 Free Trial Hosting

clock October 28, 2013 06:26 by author Ben

ASP web hosting specialist ASPHostPortal.com announced this week that it has launched a hosting package with support for Microsoft’s ASP.NET 4.5.1.
The company, which says it specializes in hosting for projects based on Windows, Microsoft SQL Server, ASP.NET, along with various other Microsoft products, launched the service this week, just a few month after the release candidate for ASP.NET 4.5.1 was issued by Microsoft.

Specialization in a certain development technology is one of the more common ways for a hosting provider to distinguish itself in a very commoditized market. ASPHostPortal.com has obviously intentionally narrowed its market to developers using Microsoft technologies.

One of the keys to focusing on a market based around a certain technology is quickly instituting support and expertise around new and emerging elements of that technology
The latest update to Microsoft’s popular .NET technology, ASP.NET 4.5.1. Here are some new features of ASP.NET 4.5.1:

  1. CLR Improvements
  2. multi-core JIT improvements
  3. Async-aware debugging
  4. Managed return value inspection
  5. ADO.NET idle connection resiliency
  6. ASP.NET app suspension
  7. On-demand large object heap compaction
  8. Better discoverability of Microsoft .NET NuGet packages
  9. Supporting large scale deployment of .NET NuGet packages


According to ASPHostPortal.com, its ASP.NET 4.5.1 offerings are distinguished by their low cost, with many of the hosting services supporting the technology being of the more expensive variety. ASPHostPortal.com’s offerings 7 Day Free Trial Hosting to all new customers.

“We pride ourselves on offering the most up to date Microsoft services. We're pleased to launch this product today on our hosting environment” said Dean Thomas, Manager at ASPHostPortal.com. “We have always had a great appreciation for the products that Microsoft offers. With the launched of ASP.NET4.5.1 hosting services, we hope that developers and our existing clients can try this new features.Now, you don’t need to spend a lot of money to get ASP.NET 4.5.1 hosting.”

For more information about new ASP.NET 4.5.1, please visit http://www.asphostportal.com.

About ASPHostPortal.com:

ASPHostPortal.com is a hosting company that best support in Windows and ASP.NET-based hosting. Services include shared hosting, reseller hosting, and sharepoint hosting, with specialty in ASP.NET, SQL Server, and architecting highly scalable solutions. As a leading small to mid-sized business web hosting provider, ASPHostPortal strive to offer the most technologically advanced hosting solutions available to all customers across the world. Security, reliability, and performance are at the core of hosting operations to ensure each site and/or application hosted is highly secured and performs at optimum level.



Cheap ASP.NET 4.5 Hosting

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions


Author Link

 photo ahp banner aspnet-01_zps87l92lcl.png

 

Corporate Address (Location)

ASPHostPortal
170 W 56th Street, Suite 121
New York, NY 10019
United States

Tag cloud

Sign in