简体   繁体   English

没有表单身份验证的ASP.NET MVC 5单点登录模式

[英]ASP.NET MVC 5 Single Sign On pattern without Forms Authentication

I'm trying to implement a single sign on pattern for my web application over several domains. 我正在尝试为我的Web应用程序在多个域上实现单一登录模式。 I was about to use Forms Authentication but I came across this: 我本打算使用表单身份验证,但遇到了以下问题:

https://softwareengineering.stackexchange.com/questions/284380/is-formsauthentication-obsolete https://softwareengineering.stackexchange.com/questions/284380/is-formsauthentication-obsolete

If it's obsolete, what's the recommended alternate solution? 如果过时了,推荐的替代解决方案是什么? I've domains like: 我有类似的域名:

  • account.domain.com (Users will login using this) account.domain.com(用户将使用此帐户登录)
  • app1.domain.com app1.domain.com
  • app2.domain.com app2.domain.com
  • app3.domain.com app3.domain.com

Also, the main issue I'm facing with Forms Authentication is the user identity. 另外,我使用表单身份验证面临的主要问题是用户身份。 I've a custom user object which has ALOT of properties. 我有一个具有很多属性的自定义用户对象。 Storing and retrieving the object from session everytime is a pain. 每次从会话中存储和检索对象都是一件痛苦的事情。 How can i overcome this difficulty? 我该如何克服这个困难?

You can use ASP.Net Identity with Claims. 您可以将ASP.Net Identity与Claims一起使用。 You do not need to use the entire ASP.Net Identity comes with ASP.Net Template. 您不需要使用ASP.Net模板附带的整个ASP.Net标识。

[assembly: OwinStartup(typeof(YOUR_APP.Startup))]    
namespace YOUR_APP
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "ApplicationCookie",
                LoginPath = new PathString("/Account/Login"),
                CookieDomain = ".domain.com",
            });
        }
    }
}

You can read more regathering how to attach claims at A primer on OWIN cookie authentication middleware for the ASP.NET developer . 您可以在ASP.NET开发人员的OWIN Cookie身份验证中间件入门上阅读有关如何附加声明的更多信息。

FYI : make sure you set same machine key in all web.config files, so that cookies can be shared between sites. 仅供参考 :请确保在所有web.config文件中设置相同的机器密钥,以便可以在站点之间共享cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM