对于我的网站,我在web.config文件中配置了1周的登录会话超时
<system.web>
<httpRuntime />
<!-- Session keeps for 7 days -->
<sessionState timeout="10080"></sessionState>
<authentication mode="Forms">
<forms loginUrl="~/" timeout="10080" slidingExpiration="true"/>
</authentication>
<!-- Configuration end -->
</system.web>
Run Code Online (Sandbox Code Playgroud)
这是登录的代码
[AllowAnonymous]
[HttpPost]
public ActionResult Login(string Login, string Password)
{
// empty passwords are not allowed
if (Password == "")
return Redirect(Request.UrlReferrer.ToString());
bool LoginResult = WebSecurity.Login(Login, Password, true);
return Redirect(Request.UrlReferrer.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我登录,关闭浏览器并再次打开它进入我的网站 - >用户已登录.我关闭浏览器,等待一段时间(约30分钟)转到我的网站 - >用户已注销.为什么?会话应存储7天,但我们甚至没有30分钟.Whan可能是问题的根源?
编辑1 主要想法是我想在几天内回到网站,并仍然使用登录用户打开它
如何在asp.net mvc中关闭表单身份验证。我具有旨在进入Web应用程序的注册,登录和忘记密码页面。最初我
我目前将asp.net mvc Web应用程序托管为单个代码库和多个数据库格式。我遇到表单在一段时间内过期的情况,而logon.aspx页面出现在主页的中间。我发现这是因为以下代码:
webconfig:
<authentication mode="Forms"><forms timeout="180000" slidingExpiration="false"/></authentication>
logon.cshtml:
FormsAuthentication.SetAuthCookie(user.UserName, false);
return RedirectToAction("Index", "Home");
Run Code Online (Sandbox Code Playgroud)
我不希望我的用户会话或表单在他们注销之前过期。如何删除身份验证模式或如何解决此超时问题?请帮忙。
这是我完整的webconfig代码:
<system.web>
<customErrors mode="Off" />
<globalization uiCulture="en-AU" culture="en-AU" />
<!--<sessionState mode="InProc" />-->
<sessionState timeout="1500"></sessionState>
<httpRuntime encoderType="AntiXssEncoder, OnlineAB" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms timeout="180000" slidingExpiration="false"/>
</authentication>
<membership>
<!--<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>-->
</membership>
<profile>
<!--<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" …Run Code Online (Sandbox Code Playgroud) 我已经尝试使用web.config和UseCookieAuthentication()方法上的所有设置,如下面列出的许多Web主题所示:
但是,尝试将这些配置或方法中所有选项的会话超时更改为1分钟(用于测试)没有任何意义,我不确定错误在哪里。以下是我更改的配置。有解决问题的主意吗?我还需要弄清楚在MVC应用程序中设置会话超时的最佳方法是什么:在web.config或Auth类中?
web.config:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" executionTimeout="60" />
<sessionState mode="InProc" timeout="1" />
<!-- For LDAP -->
<httpCookies httpOnlyCookies="true" />
<authentication mode="Forms">
<!-- Note: I also remove this part and try with only "sessionState" -->
<forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="1"
slidingExpiration="false" protection="All" />
</authentication>
</system.web>
Run Code Online (Sandbox Code Playgroud)
Startup.Auth.cs:
public void ConfigureAuth(IAppBuilder app)
{
// Code removed for brevity.
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = …Run Code Online (Sandbox Code Playgroud) authentication asp.net-mvc session session-state session-cookies