Logging in with ASP.NET

Discussion in 'ASP .Net' started by seanmatthewwalsh@hotmail.com, May 15, 2008.

  1. Guest

    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
     
    , May 15, 2008
    #1
    1. Advertisements

  2. Leon Mayne Guest

    <> wrote in message
    news:...
    > 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
     
    Leon Mayne, May 16, 2008
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    0
    Views:
    1,172
    Stefan Siegl
    Aug 27, 2003
  2. janne
    Replies:
    0
    Views:
    10,399
    janne
    Sep 10, 2004
  3. Christoph Haas
    Replies:
    0
    Views:
    618
    Christoph Haas
    Jun 12, 2006
  4. Christoph Haas
    Replies:
    1
    Views:
    647
    Vinay Sajip
    Jun 14, 2006
  5. johnny
    Replies:
    1
    Views:
    800
    Dennis Lee Bieber
    Dec 12, 2006
  6. Gal Aviel
    Replies:
    1
    Views:
    591
    Gerard Flanagan
    Mar 4, 2008
  7. Royan
    Replies:
    1
    Views:
    1,751
    Andrea Francia
    Apr 1, 2008
  8. genkuro
    Replies:
    8
    Views:
    1,911
    Stephen Hansen
    Jun 15, 2010
Loading...