【发布时间】:2015-08-01 10:58:28
【问题描述】:
我有一个旧的 webforms 应用程序,并且正在构建一个新的 MVC 版本来替换它。两者都需要并排运行一段时间,我需要单点登录才能工作。以前,用户通过 webforms 应用程序登录,我成功地设置了表单身份验证,以便 MVC 应用程序可以通过 cookie 进行身份验证。
新的登录表单现已在 MVC 应用程序中完成,用户现在需要从这些表单登录。 MVC 应用程序使用 Identity 2.x 和 OWIN。我最初尝试配置 OWIN cookie 以匹配旧版 webforms 应用程序中的设置,但无法让 webforms 应用程序读取 cookie 并验证用户身份。
从那时起,我决定将 Indentity 2.x 和 OWIN 安装到 webforms 应用程序中。我已经使设置相同。到期时间为 30 分钟,域为“”,路径为“/”。我可以看到从 MVC 应用程序生成的 cookie,但它没有被 webforms 应用程序拾取。我不断收到拒绝访问消息。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieName = Settings.Default.CookieName,
CookiePath = Settings.Default.CookiePath,
CookieDomain = Settings.Default.CookieDomain,
LoginPath = new PathString(Settings.Default.CookieLoginPath),
ReturnUrlParameter = Settings.Default.CookieReturnUrl,
ExpireTimeSpan = Settings.Default.CookieExpireTimeSpan,
SlidingExpiration = Settings.Default.CookieSlidingExpiration,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
我已将机器密钥设置(以前用于表单身份验证)保持不变。但是,我确实从两个配置文件中删除了表单身份验证。
我是否配置错误,或者是否需要更多配置才能在具有相同机器密钥的应用程序之间共享 OWIN cookie?
更新
- 使用个人用户帐户创建了一个新的网络表单应用程序。
- 添加了 MachineKey
- 将 MVC 应用程序的配置更改为标准 设置(复制新项目)
新的网络表单应用会列出 cookie,但仍不会对用户进行身份验证。
更新 请参阅下面的答案。
【问题讨论】:
标签: asp.net-mvc authentication webforms single-sign-on owin