2017-11-13 2 views
3

同じサーバーにOWIN-MixedAuthを使用して2つのmvc 5アプリケーションをセットアップしました。各アプリケーションは、別のフォルダ内にあり、次のように、独自のアプリケーションプールで構成:以下のようにそれぞれのため同じホスト名でも異なるパス上の複数のアプリケーションに対してユーザーを認証する

xyz.domain.com/MySiteA 

xyz.domain.com/MySiteB 

Web構成である

MySiteA:

<system.web> 
    <customErrors mode="Off"/> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2" /> 
</system.web> 
<!-- Enable Mixed Auth --> 
<location path="MySiteA/MixedAuth"> 
    <system.webServer> 
     <security> 
     <authentication> 
      <windowsAuthentication enabled="true" /> 
     </authentication> 
     </security> 
    </system.webServer> 
</location> 
<system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" /> 
    </modules> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <remove name="OPTIONSVerbHandler" /> 
     <remove name="TRACEVerbHandler" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
</system.webServer>` 

MySiteB:

<system.web> 
    <customErrors mode="Off"/> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2" /> 
</system.web> 
<!-- Enable Mixed Auth --> 
<location path="MySiteB/MixedAuth"> 
    <system.webServer> 
     <security> 
     <authentication> 
      <windowsAuthentication enabled="true" /> 
     </authentication> 
     </security> 
    </system.webServer> 
</location> 
<system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" /> 
    </modules> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <remove name="OPTIONSVerbHandler" /> 
     <remove name="TRACEVerbHandler" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
</system.webServer>` 

ユーザーが1つのアプリケーションにログインすると、ユーザーは自動的に2番目のアプリケーションにログインします2番目のアプリケーションの登録ユーザーではないにもかかわらず、

同様に、1つのアプリケーションからログアウトすると、自動的に2番目のアプリケーションからユーザーがログアウトします。

これは、フォームまたはウィンドウを使用して認証する場合に発生します。これを防ぐにはどうしたらいいですか?

これは私のログイン両方のアプリケーションのコードです:

[AllowAnonymous] 
    public ActionResult Login(string returnUrl) 
    { 
     // If user is already logged in 
     if (HttpContext.Request.IsAuthenticated) 
     { 
      return RedirectToAction("Index", "Manage"); 
     } 

     ViewBag.ReturnUrl = returnUrl; 
     return View(); 
    } 

そして、これは私がstartup.authに持っているものです。

var cookieOptions = 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.UseCookieAuthentication(cookieOptions); 

クッキー名を変更するオプションがありますか?

答えて

1

startup.authするのCookieNameを追加します。

var cookieOptions = new CookieAuthenticationOptions 
    { 
     AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
     CookieName = "MySiteA", 
     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.UseCookieAuthentication(cookieOptions); 
関連する問題