Logging in with ASP.NET

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
 
L

Leon Mayne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top