我正在使用FormsAuthentication和ASP.Net SqlMembership Provider.我希望在基础会话过期时提供重定向到LogIn页面的功能.
我将以下代码块放在我的BasePage OnInit中.据我测试,它始终保持重定向到LogIn页面,即使我提供了正确的UserID和密码.通过权利,它应该带我到默认页面.
if (Context.Session != null && Session.IsNewSession && this.Request.IsAuthenticated)
{
string cookieHeader = Request.Headers["Cookie"];
if (cookieHeader != null && cookieHeader.IndexOf("ASP.NET_SessionId") >= 0)
{
HttpContext.Current.Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect(FormsAuthentication.LoginUrl);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用VS 2012,IIS 7.5开发一个使用ASP.NET MVC4的Internet应用程序.我正在使用表单身份验证.我的网络配置中的设置如下.
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="30" name="userInfo" slidingExpiration="true" enableCrossAppRedirects="false" protection="All" >
<credentials passwordFormat="Clear"/>
</forms>
</authentication>
Run Code Online (Sandbox Code Playgroud)
但是IIS中的空闲超时(分钟)设置为20.当我在20多分钟后刷新我的应用程序时,我收到错误,说我的一个会话对象为空.但如果我在30分钟后刷新我的应用程序,它工作正常,它将我重定向到登录页面.输入凭据后,我正确导航到相应的页面.
我不明白为什么我会在20分钟后收到错误!(据我所知,这是IIS空闲时间设置).请帮忙.
谢谢