views:

328

answers:

2

First, I created a Login page that added a key value pair to the session and verified that on that page the session holds that pair. Next, I attempt to go to another page that looks for that pair in the session and it is not there. I've put the timeout for the session to 15000 so it won't timeout. I currently use a static class to look at the session, HttpContext.Current.Session. Each Page calls this static class to look at the session but every time the session key count = 0 except after I the pair on the login page.

public static class UserAuthenticationManager
{
    public static bool IsAuthenticated()
    {
        UserAuthenticationTicket ticket = ((UserAuthenticationTicket)HttpContext.Current.Session[DefinesPL.UserTicketSessionName]);

        string redirectUrl = String.Format(DefinesPL.LoginPage);

        if (ticket != null)
        {
            if (ticket.IsExpired())
            {
                HttpContext.Current.Session.Abandon();
                HttpContext.Current.Response.Redirect(redirectUrl, true);
            }
        }
        else
        {
            HttpContext.Current.Session.Abandon();
            HttpContext.Current.Response.Redirect(redirectUrl, true);
        }

        return true;
    }
+1  A: 

The most common cause is cookies being disabled. You'll need to require cookies, or switch to a cookieless session model, which is a little harder to work with.

Rex M
A: 

Might also want to make sure you have Global.asax added to your project. I believe i ran into this before, where a new session was created for every HTTP request.

Sergey