Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Deployment » Deploying ASP.NET 2 Web Site to Production Server: Part II

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

On the first part we discussed in detail how to move our database which contains the membership tables from the default aspnetdb Database to our database. On 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.

Technologies: ASP.NET 1.0,Visual C# .NET
Total downloads :
Total page views :  62547
Rating :
 5/5
This article has been rated :  4 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
Become a Sponsor


Related EbooksTop Videos

Introduction

On 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.

On 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 2005

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 web site 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.


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Moustafa Arafa
Moustafa Arafa, DotNet Boom supportive development manager, I have MCAD.Net, MCSD.NET, MCT & C# MVP. I have passion to learn new technologies & to share my knowledge and experience with others. contact me : http://moustafa-arafa.blogspot.com/
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments
Question about your article by Rusty On April 28, 2006

I have been struggling with this exact solution for a few weeks. Thanks for putting it together. Great job!

Just a quick thought, what happens when you try to make changes on your development server to the original project such as adding roles or making changes to the setup for authentication? Does the development environment look to the new connection or back to the original .mdf datasource?

Reply | Email | Delete | Modify | 
Re: Question about your article by Moustafa On May 5, 2006

please explain you question ?

 

Reply | Email | Delete | Modify | 
Re: Question about your article by Moustafa On December 24, 2006

the changes you did will be put it on the production DB,oyu can simply backup and restore it on your development if you need that.

 

Reply | Email | Delete | Modify | 
deploy ASP.NET by soumya On May 5, 2006

Hi,

 I am struggling with SQL Server connection problem after I deploy my ASP.NET appl. on to remote server. I followed all you instructions upto editing web.config. I cannot find a web.config where there are entries for "connectionStrings" etc. That is part of  machine.config on my local and remote systems. So, I edited my local Windows\Microsoft.NET\framework\..\machine.config by pasting the lines from your article and published the appln. again. Publishing went on ok, but I still get the same error on the accessing the website as before.

 The error apparently is because of SQL Server not allowing remote connections. But I have allowed remote connections using Surface manager on the server. Below is the error I get.

any clue ? Thanks in advance,

soumya

------------------------------------

An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735107
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
   System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +820
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +130
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
   System.Data.SqlClient.SqlConnection.Open() +111
   System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +84
   System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +197
   System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider.GetConnectionHolder() +16
   System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider.LoadPersonalizationBlobs(WebPartManager webPartManager, String path, String userName, Byte[]& sharedDataBlob, Byte[]& userDataBlob) +195
   System.Web.UI.WebControls.WebParts.PersonalizationProvider.LoadPersonalizationState(WebPartManager webPartManager, Boolean ignoreCurrentUser) +95
   System.Web.UI.WebControls.WebParts.WebPartPersonalization.Load() +105
   System.Web.UI.WebControls.WebParts.WebPartManager.OnInit(EventArgs e) +497
   System.Web.UI.Control.InitRecursive(Control namingContainer) +321
   System.Web.UI.Control.InitRecursive(Control namingContainer) +198
   System.Web.UI.Control.InitRecursive(Control namingContainer) +198
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Reply | Email | Delete | Modify | 
Re: deploy ASP.NET by Moustafa On May 5, 2006

hi somiya,

This problem occurs because the Connection string on the web.config is not correct...

please check the Server name,username and password given by the host,and the instance name....

if everything is ok on the web.config...and you follow the steps mentioned on my article....you will not get this error....

 

if you face any problem... don't hesitate to to contact me...

Reply | Email | Delete | Modify | 
Re: Re: deploy ASP.NET by soumya On May 8, 2006

Hi,

 thanks for the quick reply, I am working on it.

 First Q : Please bear with my 'newbie'ness, the web.config you have mentioned - is it the application's web.config (in our case, there is nothing in it other than the error mesg. config as it's just an example appln.) or the web.config on my system's Windows/Microsoft.NET/.../CONFIG/ ? 

 Second Q:  In the meanwhile, you have shown 'model' as database in the first part of your article. Do we have to really move the config table to model ?  I did that by mistake. Now, can I use the same tool and remove them ? Do you see any side-effects ? Our SQL Server is freshly installed, so there are no DB there as yet.

thanks,

Soumya

Reply | Email | Delete | Modify | 
Re: Re: Re: deploy ASP.NET by Moustafa On May 8, 2006

 

answer for the 1st Q :The config file is the Web.Config which resides on your project.

 

Answer Q2 : You can remove these tables by open the VS command and type

aspnet_regsql  -> window will open and give you the selection to creae or remove the membership tables.

 

Reply | Email | Delete | Modify | 
Re: Re: Re: deploy ASP.NET by Moustafa On December 24, 2006

you can install configuration manager for SQL Express 2005,and you can run the command of aspnet_regsql,and you have to make sure of the following:

1- select the right sql instance YOURSERVERNAME\SQLEXPRESS,or whatever any other name.

2- Login with the correct username/password for the sleected isntance.

hope this helps.

 

Reply | Email | Delete | Modify | 
Re: Re: Re: deploy ASP.NET by Moustafa On December 24, 2006

Hi Somaya,

No side effects if you remove the Security tables from any database.

you have to run and select your database,when u r trying to run the script of the security tables.

 

Reply | Email | Delete | Modify | 
Re: Re: deploy ASP.NET by Rahman On December 11, 2006

I am having similar problems. All I am trying to do is Part 1 where I am supposed to trabsfer all the asnetdb tables to my database. When I use aspnet_regsql, I do not even see my database that I created. Could this be because, I downloaded Microsoft SQL Server 2005 from the web as a free download;all it has is the Configuration Tool. No Management Console. Would this mean that I have to purchase SQL Server 2005 before I can follow your instructions.

Please help. Have bee banging my head for atleast a week on this.

 

Regards

Rahman

I have since solved this. Tried to delete this posting but am getting a script error.

Regards

 

 

 

Reply | Email | Delete | Modify | 
Please reply immediately if possible by Tina On October 27, 2006

My email:- tinabhate@hotmail.com

 

An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I am getting this error please help me out.....My DB is on remote server and

my website is on remote server (different machines).

 

Thanks bye

 

 

Reply | Email | Delete | Modify | 
Re: Please reply immediately if possible by Moustafa On November 5, 2006

hi Tena,

I'm sorry for replying late,since i was on vacation.

to solve your problem,on the web.config verif on the following :

1- machine name (remote server),if it has a static IP put it.

 

2- SQL instannce on that server and put it on this format :

     MACHINENAME\INSTANCENAME

 

this will solve this problem,

don't hesitate to contact me if you face any problem.

Reply | Email | Delete | Modify | 
Re: Please reply immediately if possible by Moustafa On December 24, 2006

To enable this :

Start -> SQL 2005 -> SQL Configuration Manager ->Enable namedPipes  by right click on the protocol item.

N.B.:

you u are working on sql express,then sleect the Protocols for SQL Express.

Reply | Email | Delete | Modify | 
excellent post, by steve On November 3, 2006

I knew nothing about this before I read your post. It was easy to follow

and worked perfectly,

thanks steve

Reply | Email | Delete | Modify | 
Re: excellent post, by Moustafa On December 24, 2006

thanks.

Reply | Email | Delete | Modify | 
Won't read SQL Server by Jonathan On December 1, 2006

While going through your tutorial, on Part 2 I did not have anything in there for <membership>, do I still have to put that block of go in my web.config file?
Also, I just had <roleManager enabled="true"> in my file.  Do I need to add the whole roleManager block that you have shown in my file as well?

I made my web.config file look very similar to what you have shown in your tutorial but it still won't read the SQL Server.

When I make the changes in the tutorial will I still be able to use the configuration tool to add/remove user and assign roles like I would when it is using SQLExpress?

Here is what my web.config file looks like:

<?xml version="1.0"?>

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<add name="aspnet_staterKits_TimeTracker" connectionString="Data Source=servername;Initial Catalog=TimeTracker;uid=sa;pwd=password" providerName="System.Data.SqlClient"/>

<remove name="LocalSqlServer"/>

<add name="TimeTrackerConnectionString" connectionString="Data Source=servername;Initial Catalog=TimeTracker;uid=sa;pwd=password" providerName="System.Data.SqlClient"/>

</connectionStrings>

<system.web>

<siteMap defaultProvider="AspNetXmlSiteMapProvider" enabled="true">

<providers>

<clear/>

<add name="AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>

</providers>

</siteMap>

<authentication mode="Forms">

<forms loginUrl="~/TimeTracker/login.aspx"/>

</authentication>

<compilation debug="true"/>

<customErrors mode="RemoteOnly"/>

<machineKey decryptionKey="AutoGenerate,IsolateApps"/>

<membership>

<providers>

<remove name="AspNetSqlMembershipProvider" />

<add connectionStringName="TimeTrackerConnectionString" 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>

<roleManager enabled="true"/>

<!--<providers>

<remove name="AspNetSqlRoleProvider" />

<add connectionStringName="TimeTrackerConnectionString" applicationName="/"

name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a" />

<remove name="AspNetWindowsTokenRoleProvider" />

</providers>

</roleManager>-->

</system.web>

</configuration>

Reply | Email | Delete | Modify | 
Re: Won't read SQL Server by Moustafa On December 24, 2006
you don't need to write anything by your hand,just run the asp.net security configuration tool and configure your app,it will be reflected in the web.config
Reply | Email | Delete | Modify | 
how to remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. by Rahman On December 11, 2006

How do i remove the registry value. where do i start?

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'System.Web, Version=2.0.0.0, Culture=neutral' or one of its dependencies. The system cannot find the file specified.

Source Error:

Line 54:         <remove name="AspNetSqlRoleProvider" />
Line 55:         <add connectionStringName="PropertiesConnectionString" applicationName="/"
Line 56:          name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral" />
Line 57:         <remove name="AspNetWindowsTokenRoleProvider" />
Line 58:       </providers>

Source File: D:\Clients\h&DDev\hdInvestmentsWeb\web.config    Line: 56

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web, Version=2.0.0.0, Culture=neutral' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Please help.
Regards
Rahman
 <configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>
ffffffffffff

Reply | Email | Delete | Modify | 
Re: how to remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. by Moustafa On December 24, 2006

i think there's some problem on your VS installation.

try to open new solution and try to run the asp.net security configuration tool,and see if it works or not.

if the changes you did in the asp.net configuration tool,makes this problem in the web app,this means the problem is from installation or version problem in VS 2005.

 

Reply | Email | Delete | Modify | 
SQL 2000 by dimetholether On October 10, 2007
Would this configuration changes work with SQL 2000 as well.
Reply | Email | Delete | Modify | 
ASP .net versioning by Barani On October 3, 2009
Hello,
How will you maintain versioning in asp .net web application framework 2.0.

pls gives your answer.
BaranigopalU
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved