2017-08-25 7 views
2

ASP.NET IDを使用して新しいASP.NET MVC Webサイトを作成しました。私はVisual Studio 2017で生成された標準ロジックを使用しており、個別のユーザーアカウントを選択しました。ログインタイムアウトを増やす

すべての機能は正常に動作しますが、約10〜20分以内にログインしていないようですが、これ以上ログインする必要はありません。

Googleで検索したところ、CookieAuthenticationOptions.ExpireTimeSpanの設定に関する情報が見つかりました。ただし、デバッガを使用すると、この値はデフォルトで14日間に設定されています。

Startup.Auth.cs:

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
    LoginPath = new PathString("/Account/Login"), 
    Provider = new CookieAuthenticationProvider 
    { 
     OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
      validateInterval: TimeSpan.FromMinutes(30), 
      regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) 
    }, 
    //SlidingExpiration = true,    // Default: true 
    //ExpireTimeSpan = TimeSpan.FromHours(1) // Default: 14 days 
}); 

のWeb.Config:

<system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.6" /> 
    <httpRuntime targetFramework="4.5.2" executionTimeout="240" maxRequestLength="20480" /> 
    <httpModules> 
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 
    </httpModules> 
    <customErrors mode="Off"></customErrors> 
</system.web> 
<system.webServer> 
    <modules> 
    <remove name="FormsAuthentication" /> 
    <remove name="ApplicationInsightsWebTracking" /> 
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 
    </modules> 
    <validation validateIntegratedModeConfiguration="false" /> 
<security> 
    <requestFiltering> 
     <requestLimits maxAllowedContentLength="20971520" /> 
    </requestFiltering> 
    </security> 
</system.webServer> 

だから、誰もが私が原因ログアウトを取得するまでの時間の量を増加させる方法を知っているん不活動に?タイムアウト時間をミリ秒

答えて

0

がこれはweb.configファイルに設定されますがisPersistentフラグを使用してログインしましたか?

SignInManager.PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) 

isPersistent = trueを渡すと、Cookieデータが自動的に再度ログインする必要があります。

ここで拒否されると、あなたの身元はSecurityStampValidator.OnValidateIdentityでリフレッシュされ、ログアウトされます。

独自のSecurityStampValidatorとUserManagerを実装することをお勧めします。なぜなら、OnValidateIdentityで拒否する理由をデバッグできます。

また、キャッシングをチェックしてください。キャッシングの問題があり、「古い」コンテンツを表示しているためログアウトしたように見えるかもしれません。

+2

ありがとうございますが、フォーム認証は古い方法であり、ASP.NET IDは新しい方法です。確かに、唯一の答えは私が物事を古い方法で行わなければならないということではありません。 –

1

にプロパティタイムアウト上で定義されている

<system.web> 
    <authentication mode="Forms"> 
    <forms loginUrl="~/SignIn/LoginPage" timeout="2880" defaultUrl="~/Pages/ServicesPage" /> 
    </authentication> 

次のように

+0

このフラグは、* Remember me *チェックボックスに対応していると思います。そして、はい、私はそれをチェックしようとしました。 –

+0

"validateInterval:"を数秒に設定するとどうなりますか?その時間の後にログアウトしますか? –

+0

それはしません。私はあなたが理解していることを確認してみましょう:Visual Studio 2017で*個々のユーザーアカウント*設定を使用してMVCアプリケーションを作成すると、1時間以上コンピュータを非アクティブにしておくことができますか?あなたがまだログインしている何かをクリックするか? –