Sunday 27 January 2008

ASP.NET 2.0 Configure Forms Security For SQL Server Database

I needed to set up an ASP.NET 2.0 website to use forms security using the built in login controls etc and it had to use an existing SQL Server database because the hosting the site was going onto would only provide 1 SQL Server 2005 DB (and it didnt support MS Access either).,

The tutorial on this site was great to follow:

http://aspnet.4guysfromrolla.com/articles/120705-1.aspx

As an overview though, the steps I had to take were:


  1. Use aspnet_regsql.exe, a tool located in the installation folder of the framework, that had a simple 3 step wizard. Point it at an existing database and it will create all the necessary tables, stored procedures etc for you.
  2. Create a page called login.aspx and drag a login control onto it from the login section of the toolbox.
  3. Configure the web.config to use your own database (by default it will use a sql server express db which it creates in the app_data folder of the app. Set the login page to be the one created in step 2.... http://msdn2.microsoft.com/en-us/library/6e9y4s5t.aspx
  4. Set up at least one initial user for the website by going to Project --> Configure Web Site and entering a users details. I'm using Visual Studio 2008 targeting .net 2.0, but Visual Studio 2005 must have a similar menu command if not the same.
  5. Run the site and you should be directed to the login page created in step 2, if not check your web.config is correctly configured for forms authentication. After logging on you will be redirected to the form you were running.

No comments: