![](/img/trans.png)
[英]403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied
[英]ASP.NET: 403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied
當有效用戶登錄系統並關閉瀏覽器而不注銷時,偶爾(即,不是緊隨其后,而是在第二天)它會阻止用戶重新登錄系統,並拋出以下內容:
錯誤 :403-禁止訪問:訪問被拒絕。 您無權使用您提供的憑據查看此目錄或頁面。
這個問題涉及相同的問題,但是在他的解決方案中,他決定不使用持久性cookie,因為在創建FormsAuthenticationTicket時將false作為參數傳遞,這不是理想的解決方案。
這就是我創建Cookie的方式:
private void createCookie(string username, int customerID, bool persist)
{
HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, persist);
cookie.Expires = DateTime.Now.AddHours(12);
var ticket = FormsAuthentication.Decrypt(cookie.Value);
var userData = customerID.ToString();
var newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userData);
cookie.Value = FormsAuthentication.Encrypt(newTicket);
Response.Cookies.Add(cookie);
}
關於如何解決這個問題的任何想法?
當有效用戶登錄系統並關閉瀏覽器而不注銷時,偶爾( 即,不是緊接在第二天,而是在第二天 )會阻止用戶重新登錄系統...
我可能很密集,但是代碼不是像您實現它的方式那樣工作嗎?
即,在createCookie()
:指定cookie.Expires = DateTime.Now.AddHours(12);
,它會將Cookie標記為在其發出12小時后過期。
在Asp.net 1.0中 ,如果設置了FormsAuthenticationTicket.IsPersistent
,則該票證將自動具有自頒發之日起50年的有效期限。
但是,在Asp.net 2.0中 ,情況不再如此。 如果FormsAuthenticationTicket.IsPersistent
設置為false,則該票證的有效期限與會話超時期限相同。 如果FormsAuthenticationTicket.IsPersistent
設置為true,則有效期限將默認為“表單身份驗證超時”屬性。 您將到期時間設置為要發布的時間加上12個小時,所以我希望票證在12個小時后停止工作。 假設您使用的是Asp.net 2.0+,希望這可以解釋您所看到的性能。 我建議嘗試將到期時間延長到更長的時間,然后看問題是否消失。
將自己的userData包含在auth cookie中沒有固有的問題。 在我們的一個網站中,我們使用asp.net登錄控件,並成功添加了以下事件偵聽器:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
//... unimportant code left out
//Update the users ticket with custom userInfo object
string userData = userInfo.Id.ToString("N");
HttpCookie cookie = Response.Cookies.Get(FormsAuthentication.FormsCookieName);
FormsAuthenticationTicket oldTicket = FormsAuthentication.Decrypt(cookie.Value);
FormsAuthenticationTicket newTicket =
new FormsAuthenticationTicket(
oldTicket.Version,
oldTicket.Name,
oldTicket.IssueDate,
oldTicket.Expiration,
oldTicket.IsPersistent,
userData,
oldTicket.CookiePath);
cookie.Value = FormsAuthentication.Encrypt(newTicket);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.