I have a website that is built in ASP.NET 3.5 & SQL Server 2005, using the sql membership provider, and presumably forms authentication.
Since security needs on
I think you'd be better-off using the FormsAuthentication.SetAuthCookie method rather than writing a lot of code yourself.
I believe your membership provider settings in the web.config may be conflicting with the settings you're providing in code, plus you're not providing a cookie name.
Try the following:
if (Membership.ValidateUser(userName, password))
{
FormsAuthentication.SetAuthCookie(userName, true); //Creates a cookie named "XXXAuth" - see settings in web.config below
}
In conjunction with the following settings in web.config:
Simply change the "timeout" value in the authentication block to be a longer value if you really want to create an indefinite log-in period. I believe 432000 = 5 days.
If you want your users to be able to explicitly log-out, simply call the following method in response to a button click (or whatever):
FormsAuthentication.SignOut();
Hope this helps.