C# 同一站点下多个IIS相同应用程序的登录/注销问题

C# 同一站点下多个IIS相同应用程序的登录/注销问题,c#,asp.net-mvc,owin-middleware,C#,Asp.net Mvc,Owin Middleware,我在IIS 8.0中部署了与两个站点[生产和开发]相同的应用程序,具有两个端口号。问题如下: 打开浏览器,登录第一个应用程序[生产]; 打开另一个浏览器选项卡并登录第二个应用程序[开发]; 第一个应用程序将自动注销 有没有想过两者都应该登录并使用 我的文件Startup.Auth.cs: app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerO

我在IIS 8.0中部署了与两个站点[生产和开发]相同的应用程序,具有两个端口号。问题如下:

打开浏览器,登录第一个应用程序[生产]; 打开另一个浏览器选项卡并登录第二个应用程序[开发]; 第一个应用程序将自动注销

有没有想过两者都应该登录并使用

我的文件Startup.Auth.cs:

  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"),
    SlidingExpiration = true,
    CookieName="my-very-own-cookie-name",
    //ExpireTimeSpan = TimeSpan.FromMinutes(2.0),
    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.FromHours(applTime),
          regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
      OnResponseSignIn = context =>
      {
          context.Properties.AllowRefresh = true;
          context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(idleTime);
      }

    }
  });
  app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.CreatePerOwinContext(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationSignInManager.Create);
//使应用程序能够使用cookie存储登录用户的信息
//以及使用cookie临时存储用户登录第三方登录提供商的信息
//配置登录cookie
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
slidengexpiration=true,
CookieName=“我自己的cookie名称”,
//ExpireTimeSpan=时间跨度从分钟(2.0),
Provider=新CookieAuthenticationProvider
{
//允许应用程序在用户登录时验证安全戳。
//这是一种安全功能,在您更改密码或向帐户添加外部登录时使用。
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity(
validateInterval:TimeSpan.FromHours(applTime),
regenerateIdentity:(管理器,用户)=>user.GenerateUserIdentityAsync(管理器)),
OnResponseSignIn=context=>
{
context.Properties.AllowRefresh=true;
context.Properties.ExpiresUtc=DateTimeOffset.UtcNow.AddMinutes(idleTime);
}
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

Cookie是按域设置的,您的IIS站点可能有相同的域(只是不同的端口)。尝试两个完全不同的浏览器(例如FF和IE)而不是在同一个浏览器中使用一个选项卡应该可以很好地工作。如果您必须使用相同的浏览器,请在InPrivate窗口中打开其中一个浏览器-这仍应保持Cookie分开。是的,它位于同一域[同一IP]。我尝试了IE浏览器和CHROME浏览器,带有标签和单独的窗口。两者都显示了与您提到的相同的Cookies。我的问题:我们是否可以打开两个具有相同端口差异实例的选项卡并使用它。只要域/IP相同,它们将共享相同的cookie。您可能会发现其他身份验证方案更适合您的情况(找到使用“源”(使用方案[http | https]、域和端口)而不是“主机”的身份验证方案)。您能建议我使用OWIN支持http/https的身份验证方案吗?每个域都设置cookie,并且您的IIS站点可能具有相同的域(只是不同的端口。)@HereticMonkey说的。尝试两个完全不同的浏览器(例如FF和IE)而不是在同一个浏览器中使用一个选项卡应该可以。如果必须使用同一个浏览器,请在一个InPrivate窗口中打开其中一个浏览器-这应该仍然可以将cookie分开。是的,它位于同一个域[同一IP]。我尝试了IE和CHROME浏览器,它们都有选项卡和单独的窗口。它们都显示了与您提到的相同的cookie。我的问题:我们能否打开两个具有相同端口差异实例的选项卡并使用它。只要域/IP相同,它们将共享相同的cookie。您可能会发现其他验证方案更适合您的sit评估(找到使用“origin”(使用scheme[http | https]、domain和port)而不是“host”的身份验证方案。您能给我推荐支持http/https的OWIN身份验证方案吗?