Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Forms authentication and session question

Forms authentication and session question

Scheduled Pinned Locked Moved ASP.NET
helpquestionwindows-adminsecurity
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kensai
    wrote on last edited by
    #1

    I have a website using forms authentication. I seem to have a problem with it and I'd appreciate if you could help me on this. I use <forms timeout="600"> and <sessionState timeout="600"> in web.config. In login page I have this code:

    protected void pageLogin_Authenticate(object sender, AuthenticateEventArgs e)
    {
    if (Membership.ValidateUser(this.pageLogin.UserName.Trim(),this.pageLogin.Password.Trim()))
    {
    MembershipUser u = Membership.GetUser(this.pageLogin.UserName.Trim(), false);
    Session["UserId"] = u.ProviderUserKey.ToString();
    e.Authenticated = true;
    }
    else
    {
    e.Authenticated = false;
    }
    }

    protected void pageLogin_LoggedIn(object sender, EventArgs e)
    {
    FormsAuthentication.RedirectFromLoginPage(Session["UserId"].ToString(), false);
    }

    I use Session["UserId"] on other protected pages. The problem is, sometimes when I refresh a page after a short while that uses Session["UserId"] I get null reference error on Session["UserId"] line. Why it is expiring so soon, I don't have anything modifying web.config or the website so I don't think IIS is recycling. And shouldn't it redirect to login page if session is expired? Am I missing something here? This is on WinXp sp2 and IIS6.

    A 1 Reply Last reply
    0
    • K kensai

      I have a website using forms authentication. I seem to have a problem with it and I'd appreciate if you could help me on this. I use <forms timeout="600"> and <sessionState timeout="600"> in web.config. In login page I have this code:

      protected void pageLogin_Authenticate(object sender, AuthenticateEventArgs e)
      {
      if (Membership.ValidateUser(this.pageLogin.UserName.Trim(),this.pageLogin.Password.Trim()))
      {
      MembershipUser u = Membership.GetUser(this.pageLogin.UserName.Trim(), false);
      Session["UserId"] = u.ProviderUserKey.ToString();
      e.Authenticated = true;
      }
      else
      {
      e.Authenticated = false;
      }
      }

      protected void pageLogin_LoggedIn(object sender, EventArgs e)
      {
      FormsAuthentication.RedirectFromLoginPage(Session["UserId"].ToString(), false);
      }

      I use Session["UserId"] on other protected pages. The problem is, sometimes when I refresh a page after a short while that uses Session["UserId"] I get null reference error on Session["UserId"] line. Why it is expiring so soon, I don't have anything modifying web.config or the website so I don't think IIS is recycling. And shouldn't it redirect to login page if session is expired? Am I missing something here? This is on WinXp sp2 and IIS6.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      what authentication mode did you set in IIS ? if you have used forms then you should select Anonumous authentication.

      cheers, Abhijit

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups