我們聘請所需外的過程SQL會話狀態,ASP.NET MVC 3.5和1.0表單中使用IIS 7ASP.NET 3.5 MVC1 - 用戶隨機未經認證/重新登錄
用戶的會話驗證是在登錄時正確設置,並按預期超時,將其重定向到特殊的「超時」登錄頁面。問題在於一些(不是全部)用戶登錄,並且(從我所知道的)立即未經身份驗證並且需要重新登錄(即重定向到原始「登錄」頁面)。
任何人都可能有一個想法,爲什麼我們的用戶間歇性被踢出?
編輯:我已經在每個Application_AuthenticateRequest事件上添加了日誌記錄,我可以告訴你,在用戶啓動之前,Auth票證都已通過身份驗證,持續兩天後過期並且請求也通過身份驗證。到達登錄頁面後,用戶不再通過身份驗證。
編輯#2:我們取得了一些進展,看起來好像用戶可能未經過身份驗證,因爲此Web應用程序正在尋找父應用程序中的腳本和其他內容,而其中的用戶未通過身份驗證。列入這些腳本的原始格式如下:
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
我已將其更正爲:
<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript"></script>
ANSWER在我們的.master頁以上改變我們的腳本引用解決了問題。它明確告訴應用程序查看當前應用程序的根文件夾。感謝所有幫助過的人。我希望我可以標記不止一個答案!
下面是我們的登錄操作:
[AcceptVerbs(HttpVerbs.Post)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
Justification = "Needs to take same parameter type as Controller.Redirect()")]
public virtual ActionResult LogOn(string userName, string password, string returnUrl)
{
if ((HttpContext.Current.User == null) || (!HttpContext.User.Identity.IsAuthenticated))
{
if (!ValidateLogOn(userName, password))
{
try
{
return View();
}
catch (Exception ex)
{
throw new Exception(string.Format("User validation failed at LogOn: {0}", ex.ToString()));
}
}
}
bool rememberMe = true;
FormsAuth.SignIn(userName, rememberMe);
Session["userName"] = userName;
if (!String.IsNullOrEmpty(returnUrl))
{
try
{
return Redirect(returnUrl);
}
catch (Exception ex)
{
throw new Exception(string.Format("User redirect to returnUrl ({0}) failed: {1}", returnUrl, ex.ToString()));
}
}
else
{
try
{
return RedirectToAction("Index", "RodWebUI");
}
catch (Exception ex)
{
throw new Exception(string.Format("User redirect to action: Index, controller: RodWebUi failed: {0}", ex.ToString()));
}
}
}
下面是我們timeoutlogon行動:
public virtual ActionResult TimeOutLogon()
{
try
{
FormsAuth.SignOut();
ViewData["TimeoutMsg"] = "Session timed out. Please log back in.";
return View();
}
catch (Exception ex)
{
throw new Exception(string.Format("Error with redirecting to TimeOutLogon: {0}", ex.ToString()));
}
}
因爲我已經添加了以下檢查,以我們的Global.asax中記錄的當前狀態請求和授權票。在被踢回LogOn之前,所有事情都經過認證和確定。
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = identity.Ticket;
LogFunctionCall(HttpContext.Current.User.Identity.Name, "", "User Authentication Check", "",
string.Format("Auth ticket is expired: {0}, expiration date: {1}, is persistent: {2}, issued: {3}",
ticket.Expired, ticket.Expiration, ticket.IsPersistent, ticket.IssueDate), "", 0);
LogFunctionCall(HttpContext.Current.User.Identity.Name, "", "User Authentication Check Line #2", "",
string.Format("Raw URL: {0}, Request is authenticated: {1}", HttpContext.Current.Request.RawUrl, HttpContext.Current.Request.IsAuthenticated), "", 0);
}
}
}
}
不,returnUrl沒有指向登錄頁面。用戶登錄並導航到我們網站上的另一個頁面時,他們被重定向到登錄頁面,並且在重定向之前,returnUrl顯示了預期的URL。如果用戶已經登錄並且他們要導航到登錄頁面(他們將通過在地址欄中輸入url來完成登錄),他們將被註銷,因爲不提供密碼。 – alan 2011-01-31 21:33:41
@alan:偏題:在這種情況下,我不會註銷用戶。簡單的重定向到「索引」會更安全。 – msms 2011-01-31 21:39:01
我注意到,我還會更新我的登錄操作代碼以反映新的更改。而不是重新驗證用戶,我會檢查用戶是否通過身份驗證。 – alan 2011-01-31 22:17:02