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.

Saturday 26 January 2008

Difficult to find if error

I just spent a little while resolving an error... and it turned out to be a stupid little syntax error.

I had written something similar to the following:

if(evaluate1evaluate2evaluate3&&evaluate4);
{
// Do Something
}

The error was that, even though I thought it shouldn't, the Do Something was always doing something.

I started looking into the evaluations in the if statement and trying to work out why they seemed to be evaluating to true when I thought they shouldn't be.....

Then I spotted the problem....

You might have spotted it straight away when you saw the statement above....

I had put a semi colon after the if statement, before the curly bracketed section I wanted to execute if the if evaluated to true.

Once I had seen it, it made perfect sense as to why the behaviour was happening and I could have kicked myself.

Definitely the first thing I will look for if I experience this behaviour again.

Friday 25 January 2008

Hello World!

Hello all,

I am a .net software developer from the North East of England. My background is primarily in enterprise C# Web applications but have also worked on VB.NET and VB6 Windows applications.

I have MCSD for .NET certification.