Login Form & Cookie Issues

Results 1 to 2 of 2

Thread: Login Form & Cookie Issues

  1. #1
    Join Date
    Dec 1969

    Default Login Form & Cookie Issues

    My Question:<BR><BR> I have a login form (username, password, login image) inside of a user control. The login form works fine to a database and authenticates/denies appropriately.<BR><BR> After successful login, the login area (where the username textbox and password textbox is) changes to the user&#039;s menu. This works great! However when the user moves to another page within the site it asks for the username and password again because it cannot tell that the user is logged in. I stored "loggedin" session variable so that the application could tell the user was logged in across the application to solve the problem. Is this the best practice or is there a better way to carry logged in information from page-to-page? Cookies maybe?<BR><BR>Finally, and more importantly, after successful login it stores a cookie for just the username. In theory, when a user returns to the site it should have the username already in the username textbox. However if a new user comes to the site and the cookie doesn&#039;t exist at all, it gives me this error:<BR><BR>"System.NullReferenceException: Object reference not set to an instance of an object."<BR><BR>Which tells me that the cookie doesn&#039;t exist. So how do I code the page to ignore the following line if the cookie doesn&#039;t exist?:<BR><BR>Username.Text = Request.Cookies("cookiename").Value<BR><BR>Is there an equivalent in ASP.NET for "if exists" or "isnull()"?<BR><BR>Thanks for your time in advance,<BR>Adam Frazier

  2. #2
    Join Date
    Dec 1969

    Default RE: Login Form & Cookie Issues

    For the test try :-<BR>If Not Request.Cookies("cookiename") Is Nothing Then<BR><BR>For the more general question, it might be worth your while to take a look at Forms Authentication.<BR>The Quick Start tutorials are a good place to start :-<BR>http://www.asp.net/Tutorials/quickstart.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts