2011-08-16 82 views
0
protected void Page_Load(object sender, EventArgs e) 
     { 
      if (HttpContext.Current.User.Identity.IsAuthenticated) 
      { 
       Session["User"] = "Authenticated"; 
       Session["Username"] = HttpContext.Current.User.Identity.Name; 
       Response.Redirect("HomePage.aspx"); 
      } 

     } 

protected void btnSubmit_Click(object sender, EventArgs e) 
     { 
      int recordExistCount = fc.Authenticate(txtUsername.Text.Trim(), txtPassword.Text.Trim()); 
      if (recordExistCount == 1) 
      { 
       Session["User"] = "Authenticated"; 
       Session["Username"] = txtUsername.Text.Trim(); 
       fc.IsOnlineRecord(Session["Username"].ToString(),true); 
       var ticket = new FormsAuthenticationTicket(2,Session["username"].ToString(),DateTime.Now,DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), true,"",FormsAuthentication.FormsCookiePath); 
       var encryptedTicket = FormsAuthentication.Encrypt(ticket); 
       var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) 
       { 
        HttpOnly = FormsAuthentication.RequireSSL, 
        Path = FormsAuthentication.FormsCookiePath, 
        Domain = FormsAuthentication.CookieDomain 
       }; 
       Response.Cookies.Add(cookie); 
       Response.Redirect("HomePage.aspx"); 
      } 

<authentication mode="Forms"> 
     <forms loginUrl="LoginPage.aspx" 
      protection="All" 
      timeout="60" 
      name=".ASPXAUTH" 
      path="/" 
      requireSSL="false" 
      slidingExpiration="true" 
      defaultUrl="HomePage.aspx" 
      cookieless="UseDeviceProfile" 
      enableCrossAppRedirects="false"/> 
     </authentication> 

當頁面閒置超過10分鐘時,頁面超時。我不知道發生了什麼問題?FormsAuthentication超時問題

+0

你在開發過程中在SSL運行? – kd7

+0

requireSSL表單標籤的屬性設置爲false –

+0

看看這個,它不一樣但相似,差不多相反http://www.hanselman.com/blog/WeirdTimeoutsWithCustomASPNETFormsAuthentication.aspx – kd7

回答

0

它可能是您的會話超時,而不是表單。你有沒有在Web.Config中設置會話超時?這可以在sessionState元素來完成

檢查(system.web元素內),此鏈接獲取更多信息:http://msdn.microsoft.com/en-us/library/h6bb9cz9%28v=VS.100%29.aspx

+0

我已經包含sessionstate標記並將超時指定爲60分鐘 –