Att*_*ers 6 authentication asp.net-mvc webforms single-sign-on owin
我有一个遗留的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))
}
});
Run Code Online (Sandbox Code Playgroud)
我已经将机器密钥设置(以前用于表单身份验证)保持不变.但我删除了两个配置文件中的表单身份验证.
我是否错误配置了某些内容,或者是否需要更多配置才能在具有相同机器密钥的应用程序之间共享OWIN cookie?
UPDATE
新的webforms应用程序列出了cookie但仍未对用户进行身份验证.
更新 请参阅下面的答案.
创建两个新应用程序并使其正常工作后,我制定了一个基线并从那里向后工作,直到实现应用程序之间单点登录的目标。我发现了很多事情,包括;
<httpRuntime targetFramework="4.5"/>
就是您所需要的。所以最后我确实需要将 Identity 2.x 和 OWIN 添加到我的旧版 Webforms 应用程序中,基本上升级到 4.5 中的新身份验证管道以使其正常工作。
希望这篇文章可以帮助大家节省一些宝贵的时间和精力。
重要更新: 尝试在 IIS 中部署时,即使您没有在配置中指定任何计算机密钥(并且在本地工作),部署后也不会工作。最后,我使用 MVC 应用程序作为父应用程序,使用旧版 Webforms 应用程序作为子应用程序,这要求父应用程序进行以下配置;
<machineKey decryptionKey="AutoGenerate" validationKey="AutoGenerate" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3520 次 |
最近记录: |