2014-10-17 207 views
1

如果我將會話超時設置爲少於20分鐘,則一切工作正常。ASP.NET MVC會話超時不起作用

但是,如果它是> 20分鐘它不工作。它發生在VS 2013和Production IIS上。

這是我使用的代碼。

如何解決該問題?謝謝!

STARTUP.AUTH

public partial class Startup 
    { 
     public void ConfigureAuth(IAppBuilder app) 
     { 
      var sessionTimeout = 5; 

      app.UseCookieAuthentication(new CookieAuthenticationOptions 
      { 
       ExpireTimeSpan = TimeSpan.FromMinutes(sessionTimeout), 
       AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
       LoginPath = new PathString("/Account/Login") 
      }); 
} 

的Global.asax

protected void Session_Start(object sender, EventArgs e) 
     { 

       Session.Timeout = 5; 

     } 

附: WEB.CONFIG

<sessionState mode="InProc" /> 

    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login" defaultUrl="~/Account/Login" name="MyApp123" /> 
    </authentication> 
+0

您是否嘗試過使用ExpireTimeSpan = new TimeSpan(0,0,5,0) – DSR 2014-10-17 13:53:55

+2

解釋「無效」的含義。沒有超時?它仍然在20分鐘時間?根本沒有會話?你如何衡量它是否超時?僅供參考,身份驗證超時不是會話超時,它們是兩件不同的事情。 – 2014-10-17 16:29:13

+0

@ErikFunkenbusch看,我通過我的代碼設置超時10小時。但它會在20分鐘後過期。這是問題。 – 2014-10-17 16:35:24

回答

2

這聽起來像你在你的web.config有FormsAuthentication配置仍然。您正在使用與舊的FormsAuthentication衝突的ASP.NET身份。

改成這樣:

<authentication mode="None"/> 

並確保你有這樣的:

<system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" /> 
    </modules> 
</system.webServer> 

你也可以生成與asp.net身份默認的Web項目,並期待在網上。配置,它將具有相同的條目。請注意,V1 Identity模板在remove元素中使用了「FormsAuthenticationModule」而不是「FormsAuthentication」的拼寫錯誤。如果您使用v2或更高版本,他們會修正該錯字。