跨子域的 ASP.NET Identity Cookie [英] ASP.NET Identity Cookie across subdomains

查看:31
本文介绍了跨子域的 ASP.NET Identity Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于表单身份验证,我在 web.config 中使用了它(注意域属性):

<forms loginUrl="~/Account/Login" timeout="2880" name=".ASPXAUTH" protection="Validation" path="/" domain=".myserver.dev"/></认证>

如何为 Mvc 5 中的新 ASP.NET Identity Framework 配置跨子域的单点登录?

更多信息:

我正在创建一个多租户应用程序.每个客户端都将位于一个子域中:

client1.myapp.com

client2.myapp.com

我希望用户能够登录到 client1.myapp.com,然后转到 client2.myapp.com 并仍然登录.这是易于使用表单身份验证.我正在尝试弄清楚如何使用新的身份框架来做到这一点.

编辑

这是最终对我有用的代码:

app.UseCookieAuthentication(new CookieAuthenticationOptions{AuthenticationType = "应用程序",LoginPath = "/Account/Login",CookieDomain = ".myapp.com"});

解决方案

在 Startup.Auth.cs 中,您将看到如下内容:

对于 RC:

app.UseSignInCookies();

这在 RTM 中被删除并替换为 cookie auth 的显式配置:

 app.UseCookieAuthentication(new CookieAuthenticationOptions {AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Account/Login")});

CookieAuthenticationOptions 类有一个 CookieDomain 属性,我相信这正是您要寻找的.

For forms authentication I used this in web.config (note the domain attribute):

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" name=".ASPXAUTH" protection="Validation" path="/" domain=".myserver.dev" />
</authentication>

How is a single sign-on across subdomains configured for the new ASP.NET Identity Framework in Mvc 5?

More Info:

I am creating a multitenant application. Each client will be on a subdomain:

client1.myapp.com

client2.myapp.com

I want a user to be able to sign on to client1.myapp.com and then go to client2.myapp.com and still be signed in. This was easy with forms authentication. I'm trying to figure out how to do it with the new Identity Framework.

EDIT

Here is the code that eventually worked for me:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
  AuthenticationType = "Application",
  LoginPath = "/Account/Login",
  CookieDomain = ".myapp.com"
});

解决方案

In Startup.Auth.cs, you will see something like:

for RC:

app.UseSignInCookies();

This was removed in RTM and replaced with the explicit configuration of the cookie auth:

    app.UseCookieAuthentication(new CookieAuthenticationOptions {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login")
    });

The CookieAuthenticationOptions class has a CookieDomain property which is what you are looking for I believe.

这篇关于跨子域的 ASP.NET Identity Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆