在我的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>
我有以下问题
应该是什么,因为我使用滑模authention由于该会议将表单验证之前到期到期里面会话超时值。 如何保护呢?
formauthentication注销后,我想在logout.aspx重定向页面,但它会自动重定向我在loginpage.aspx。 这怎么可能?
- 为了安全起见:超时(会话)<=超时(FormsAuthentication)* 2
- 如果你想显示比在验证超时后loginUrl属性指定的其他页面,你需要手动处理此为ASP.NET并没有提供这样做的一种方式。
为了达到#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
}
对于具有会话依赖的网站,你可以简单地签订在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();
}
}
这使得它,以便新一届=新的认证,期。