Link to home
Start Free TrialLog in
Avatar of sinsoush
sinsoush

asked on

Publish ASP.NET and ASPNETDB.mdf into production

Could someone please explain to me, step by step, how to publish an ASP.NET application with login security.  I created a user within the web administration tool in Visual Studio 2005, which created the ASPNETDB.mdf database.  

Although I can login successfully when I run the app in VS2005, when I deploy it to a production server it will not run.  My understanding is the ASPNETDB.mdf needs to be attached to my sql server.  I have attempted this but still not working.  

Can someone please take me through the "cradle to grave" steps for this process.  I have spent three days in forums with no luck.  
Avatar of hemaldesai
hemaldesai
Flag of India image

Ok First thing i'll suggest is not to use two different DBs for your Authentication and one for your application. There is a commandline utility which is located ?%system%/WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe /w

this will launch a wizard, you have to provide it with the DB you want to upgrade to work as a ASPNETMembership and Role Provider. Once this steps are done your DB will be able to manage your Membership.

Next Step is to modify your web.config file to hand the membership via this new DB.

Step 1 : Create a Connection String which will be pointing to this new DB which is attached to a SQL server.
Step 2 : Update your <membership> Tag & Add Provider
Step 3 : Update your <Role> tag & Add Provider
Step 4 : Run ASP.net Administration console and change the provider to this new providers.
Step 5 : setup your user accounts and you are done.

For your production server.
Step 1 : Take the backup of this DB and restore it on the server.
Step 2 : update you connection string with respect to your new DB server
Step 3 : Deploy your site.

Regards
Hemal

Attached is the a sample of web.config parts you need to edit

	<connectionStrings>
		<add name="myConnectionString" connectionString="Data Source=MyServer;Initial Catalog=myDB;Persist Security Info=True;User ID=MyUser;Password=MyPassword" providerName="System.Data.SqlClient"/>
	</connectionStrings>
 
		<membership defaultProvider="MyMembershipProvider">
			<providers>
				<remove name="AspNetSqlMembershipProvider"/>
				<add connectionStringName="myConnectionString" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" name="MyMembershipProvider" applicationName="/" type="System.Web.Security.SqlMembershipProvider"/>
			</providers>
		</membership>
		<roleManager defaultProvider="MyRoleProvider" enabled="true">
			<providers>
				<remove name="AspNetSqlRoleProvider"/>
				<add type="System.Web.Security.SqlRoleProvider" name="MyRoleProvider" applicationName="/" connectionStringName="myConnectionString"/>
			</providers>
		</roleManager>

Open in new window

Avatar of sinsoush
sinsoush

ASKER

Thank you Hemal,
Please forgive me b/c I have going to take this slowly...your solutions sounds like you know what you are talking about and i want to do your steps correctly.

In the web.config file you included you have two section that state: applicationName="/"
If my test application is simply called WebSite5, should this change to applicationName="/WebSite5" ?

I tried making the web.config changes you recommend and when I build my application I get an error that says: Unrecognized configuration section membership

Please see the screen shot attached...thank you for working with me on this!

Travis
Unrecognized-configuration-secti.JPG
ASKER CERTIFIED SOLUTION
Avatar of hemaldesai
hemaldesai
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hemal, you are very smart and excellent at what you do!

Thank you very much for your quick and to the point solution...it works perfect!!!

Cheers,
Travis
Very well documented explanation...very helpful
U r most wellcome Travis,

u can reach me at hemal.desai@gmail.com any time.

if u need some materials to learn please let me know.

hemal