在我的asp.net网站中,我使用具有以下配置的asp.net表单身份验证
<authentication mode="Forms">
<forms loginUrl="~/Pages/Common/Login.aspx"
defaultUrl="~/Pages/index.aspx"
protection="All"
timeout="30"
name="MyAuthCookie"
path="/"
requireSSL="false"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" >
</forms>
</authentication>
我有以下问题
发布于 2009-09-24 10:08:50
要实现#2,您可以手动检查cookie及其AuthenticationTicket是否过期,如果过期,则重定向到您的自定义页面。
您可以在以下事件之一中执行此操作:AcquireRequestState、AuthenticateRequest。
事件中的示例代码可能如下所示:
// Retrieve AuthenticationCookie
var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (cookie == null) return;
FormsAuthenticationTicket ticket = null;
try {
ticket = FormsAuthentication.Decrypt(cookie.Value);
} catch (Exception decryptError) {
// Handle properly
}
if (ticket == null) return; // Not authorised
if (ticket.Expiration > DateTime.Now) {
Response.Redirect("SessionExpiredPage.aspx"); // Or do other stuff here
}
发布于 2012-05-31 22:22:50
对于具有会话依赖关系的站点,您可以使用global.asax中的会话启动事件简单地注销过时的身份验证:
void Session_Start(object sender, EventArgs e)
{
if (HttpContext.Current.Request.IsAuthenticated)
{
//old authentication, kill it
FormsAuthentication.SignOut();
//or use Response.Redirect to go to a different page
FormsAuthentication.RedirectToLoginPage("Session=Expired");
HttpContext.Current.Response.End();
}
}
这使得新的会话=新的认证,句号。
https://stackoverflow.com/questions/1470777
复制相似问题