2

Google2ログインでmvc5アプリを作成しました)Identity2でmvc5アプリを作成しましたが、セッションクッキーを使用するように設定してブラウザが終了したときに期限切れになるように設定するにはどうすればいいですか?

セッションクッキーを使用するように設定するにはどうすればいいですか?ブラウザが終了したときにセッションクッキーが期限切れになるようにします。 ホットスワップシートを使用する可能性のある学生がアプリを使用するため、ブラウザが終了するとログインが切れる必要があります。

これはデフォルトであることを意味するSOの記事を読んでいますが、ブラウザを閉じてサイトに戻ったときに、Googleログインを記憶しています。

申し訳

編集は誰もバブルを破裂するが、これは重複しません。

「answer」の設定が変更された後、Chromeで再現され、IEでも再生されます。これはChromeの問題ではなくAsp.net ID 2 + Googleログインの問題です。私は修正しようとしているセットアップヘルプのスタートアップ認証ファイルを追加する

編集

using System; 
using System.Configuration; 
using Microsoft.AspNet.Identity; 
using Microsoft.AspNet.Identity.Owin; 
using Microsoft.Owin; 
using Microsoft.Owin.Security.Cookies; 
using Microsoft.Owin.Security.Google; 
using Owin; 
using StudentPortalGSuite.Models; 

namespace StudentPortalGSuite 
{ 
    public partial class Startup 
    { 
     // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 
     public void ConfigureAuth(IAppBuilder app) 
     { 
      // Configure the db context, user manager and signin manager to use a single instance per request 
      app.CreatePerOwinContext(ApplicationDbContext.Create); 
      app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 
      app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); 

      // Enable the application to use a cookie to store information for the signed in user 
      // and to use a cookie to temporarily store information about a user logging in with a third party login provider 
      // Configure the sign in cookie 
      app.UseCookieAuthentication(
      new CookieAuthenticationOptions 
      { 
       AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
       LoginPath = new PathString("/Account/Login"), 
           Provider = new CookieAuthenticationProvider 
       { 
        // Enables the application to validate the security stamp when the user logs in. 
        // This is a security feature which is used when you change a password or add an external login to your account. 
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
         validateInterval: TimeSpan.FromMinutes(30), 
         regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager) 
         ) 
       }, 
      });    
      app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 

      // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. 
      app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); 

      // per https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on - EWB 
      //dev-jcsn email 
      app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() 
      { 
       ClientId  = "...", 
       ClientSecret = "..." 


      }); 
      //}); 
     } 
    } 
} 

EDIT ユースケースは、我々のアプリが教室で使用されているので、あること学生Aログアウトする代わりにブラウザを閉じ、次のユーザーがログインしようとします。それが現れたとき、彼らはユーザーAのアカウントにautologgedされます。

ログインページにリダイレクトされたときにユーザーを100%ログアウトする方法もありますが、試したことのあるすべての方法が機能していません。ログインコントローラのメソッドの先頭でこれを呼び出す

+0

私はID 2とGoogleでMVC5をテストしました。ブラウザが終了すると、デフォルトでログアウトされます。何かが誤ってどこかに設定されていなければなりませんが、ここで十分な詳細がわかりません。 – Matthew

+0

私はそれが設定エラーだと思っていますが、私が読んだことのすべては、デフォルトでオンになっていると言います。 –

+0

おそらくGoogleアカウントのセッションが有効なためです。彼らはGoogleからサインアウトする必要があります。あなたは生徒のために別々のネットワークログインを作成することはできますか? –

答えて

0

は、問題を解決しました。

Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);// https://stackoverflow.com/questions/28999318/owin-authentication-signout-doesnt-seem-to-remove-the-cookie - stralos s answer 
    Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); 
1

たぶん、あなたは、ページ上のウィンドウクローズイベントをキャッチし、呼び出すことができlogoutメソッド

$(window).on("beforeunload", function() { 
    //ajax call to a post controller that logs the user out 

}) 
+0

これは、信頼できるログアウト方法を見つけることができればよりうまくいくはずです...私はログインページで私のページに用意されているすべてのメソッドを呼び出していますが、 '放棄されたセッション'をログアウトすることはできません。 –

+1

この方法がありますか? [HttpPost] [ValidateAntiForgeryToken] タスク<のActionResult>ログオフ(){ VARユーザー=非同期公衆UserManager.FindByNameAsync(User.Identity.Name)を待ちます。 AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); はUserManager.UpdateSecurityStampAsync(user.Id)を待機します。 return RedirectToAction( "Login"、 "Account"); } – katibaer

+0

非同期ではないことを除いて –

関連する問題