Logging in with ASP.NET

  • Thread starter Thread starter seanmatthewwalsh
  • Start date Start date
S

seanmatthewwalsh

Hi

I have a single login for a website, so my C# code is simply:

if (textUserName.Text.ToLower() == "admin" &&
textPassword.Text.ToLower() == "password")
{
Session["LoggedIn"] = true;
Response.Redirect("MyHome.aspx", false);
}
else
{
pResponse.Attributes["class"] = "Error";
pResponse.InnerText = "Login Failed. Please try again.";
pResponse.Visible = true;
}

I'm not sure if this is the BEST way, though. I've seen there is so
much functionality in the System.Web.Security library, but for a
simple case like this, is it worthwhile?

I get an intermittent problem where (on localhost, so far) my session
seems to expire quite quickly. I'm not sure if this is because of the
way I'm logging in, or if it's because of re-compilations while
debugging, so if the method above looks like it will create problems,
please let me know!!

Thanks
Sean
 
Hi

I have a single login for a website, so my C# code is simply:

if (textUserName.Text.ToLower() == "admin" &&
textPassword.Text.ToLower() == "password")
{
Session["LoggedIn"] = true;
Response.Redirect("MyHome.aspx", false);
}
else
{
pResponse.Attributes["class"] = "Error";
pResponse.InnerText = "Login Failed. Please try again.";
pResponse.Visible = true;
}

I'm not sure if this is the BEST way, though. I've seen there is so
much functionality in the System.Web.Security library, but for a
simple case like this, is it worthwhile?

I get an intermittent problem where (on localhost, so far) my session
seems to expire quite quickly. I'm not sure if this is because of the
way I'm logging in, or if it's because of re-compilations while
debugging, so if the method above looks like it will create problems,
please let me know!!

The problem with what you are doing is that you would have put a check on
each page which checks to see if they are logged in or not and redirect them
to the login page if they arn't. You should really use Forms Authentication
which will take all the work out for you. Have a look at some articles like:

http://www.ondotnet.com/pub/a/dotnet/2003/01/06/formsauthp1.html
http://msdn.microsoft.com/en-us/library/aa480476.aspx
http://www.4guysfromrolla.com/webtech/110701-1.shtml
 
Back
Top