Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Persistent Cookie for Login not working

Posted on 2006-06-21
8
Medium Priority
?
347 Views
Last Modified: 2008-02-26
The remember me feature for login is not working for me.  All other aspects seem to work fine.  When the timeout expires it makes me log in again.  I was under the impression that entering "True" in the redirectfromlogin would set a persistant cookie that overrides the timeout.  What am I doing wrong?



Here is the relevant web config
**************************************
 <authentication mode="Forms">
        <forms loginUrl="admin/login.aspx" name="UCLGN" timeout="1" protection="All" ></forms>
      </authentication>


 <location path="admin">
    <system.web>
      <authorization>
        <deny users="?" />
      </authorization>
    </system.web>
  </location>
************************************

I set the timeout to 1 to exagerate the problem for testing.

Here is my login page code
************************************
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            FormsAuthentication.SignOut()
        End If
    End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("UC").ConnectionString)
        Dim cmd As New SqlCommand("SELECT * FROM vUsers WHERE username = @username and password = @password", conn)
        cmd.Parameters.AddWithValue("@username", Me.txtUserName.Text)
        cmd.Parameters.AddWithValue("@password", Me.txtPassword.Text)
        conn.Open()
        Dim dtr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        If dtr.Read Then
            FormsAuthentication.RedirectFromLoginPage(dtr("idUser"), Me.chkRememberMe.Checked)
        Else
            Me.lblLoginMessage.Text = "Invalid Login"
        End If
    End Sub

0
Comment
Question by:dbashley1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 16952356
looks like you are missing the cookie path in your web.config

<authentication mode="Forms">
        <forms loginUrl="admin/login.aspx" name="UCLGN" timeout="1" path="/" protection="All" ></forms>
      </authentication>

HTH
0
 

Author Comment

by:dbashley1
ID: 16952689
sammy,

I added that...it didn't seem to make a difference.

0
 

Author Comment

by:dbashley1
ID: 16952939
In my temp internet files I see a single cookie with an expiration one minute after creation.  Should there be another cookie for the persistant feature?
0
 

Author Comment

by:dbashley1
ID: 16953317
I found this article.....
http://blogs.msdn.com/dansellers/archive/2006/02/15/532359.aspx

Indicating that in 2.0  both the session and persistant cookie timeout is controled by the timout value in your web config.

0
 
LVL 27

Accepted Solution

by:
Sammy Ageil earned 1000 total points
ID: 16957347
dbashley,
in asp.net 2.0 setting authentication cookie without a sliding expiration will cause the framework to create a cookie using something like this DateTime.Now.AddMinutes(T), where T is the time you have configured in your web.config as the timeout time.  if you omitted that you would default to 30 minutes

I would clear the temp file completely, login and check it out see if the cookie have been written, another option is to use a different browser for testing purposes.

Regards
Sammy
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question