Deploying ASP.NET 2 Web Site to Production Server: Part II

Introduction

In the first part we discuss in detail how to move our database which contains the membership tables from the default aspnetdb Database to our database.

In this part we will show how to change the default settings of asp.net membership and role providers to read from tables which stored on our database.

Prerequisites

  • Visual Studio

Overview

ASP.net 2 is shipped with default membership providers and roles provider classes, the default settings of asp.net 2 web site is to read from these providers which was stored on the aspnetdb database.

To successfully change the default settings of providers to your providers,you have to:

  1. Change the Default Connection to SQL Express Instance.
  2. Change the membership provider.
  3. Change the roles provider.
  4. Change the Personalization provider.

Membership provider is responsible for storing the membership users and their roles.

Roles Provider is responsible for Role management.

And Personalization provider is responsible for personalization in the web site and web parts.

A) Change the default connection to SQL Express Instance:

By default, the asp.net web site when tries to connect to a database it search first to the installed sqlExpress on the machine, that's why you have to change the default connection string to direct the web site to read from the connection string element on the web.config.

First, open your web.config and write this element on the connection string element.

<connectionStrings>
  <remove name="LocalSqlServer" />
  <add name="MyDBConnectionString" connectionString="Data Source=.;Initial Catalog=MYDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

On this section remove LocalSqlServer means that you want to point to the installed SQL Server instance not the SQL Express Instance.

B) Change the default membership provider:

Change the default membership element to point to your connection string not to the SqlExpress default connection string.

<membership>
   <providers>
    <remove name="AspNetSqlMembershipProvider" />
    <add connectionStringName="MyDBConnectionString" enablePasswordRetrieval="false"
     enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/"
     requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5"
     minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1"
     passwordAttemptWindow="10" passwordStrengthRegularExpression=""
     name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </providers>
</membership>

On connection string element of the membership element, you have to edit this element and write the key of your connection string in the web.config.

C) Change the default role provider:

Before do this step, take care that Role provider should be enabled, you can enable role provider from asp.net configuration tool.

After you enable the role manager, you will notice that Role Manager element was added to your web.config and enabled=true .

<roleManager enabled="true">
   <providers>
    <remove name="AspNetSqlRoleProvider" />
    <add connectionStringName="MyDBConnectionString" applicationName="/"
     name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <remove name="AspNetWindowsTokenRoleProvider" />
   </providers>
</roleManager>

Like you did on the membership provider, do the same on the role manager by edit the connection string by type the key of the connection string you want to use.

D) Change the default personalization provider:

This step is required if your web site contains Web Parts only, if your  web site contains web parts you have to edit the personalization element on the web.config.

<webParts>
    <personalization  defaultProvider="AspNetSqlPersonalizationProvider">
        <providers>
             <remove name="AspNetSqlPersonalizationProvider" />
             <add name="AspNetSqlPersonalizationProvider"
             type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
             connectionStringName="MyDBConnectionString"
             applicationName="/" />
        </providers>
    </personalization>
</webParts>

By changing the above 4 provider then your website have to be ready to deploying to the production server, at this mammon all the providers such as membership, role, personalization was configured directly to load data from your database.


Similar Articles