跨子网域ASP.NET身份饼干 [英] ASP.NET Identity Cookie across subdomains

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

问题描述

有关窗体身份验证我在web.config中使用这个(注意域属性):

 <身份验证模式=表格>
  <ASPXAUTH。myserver.dev形式loginUrl =〜/帐号/登录超时=2880的名字= =保护验证路径=/域= />
< /认证>

如何是一个单点登录跨MVC中5配置了新的ASP.NET身份框架子域?

更多信息:

我创建一个多租户应用程序。每个客户端将在一个子域:

client1.myapp.com

client2.myapp.com

我希望用户能够登录到 client1.myapp.com 然后转到 client2.myapp.com ,但仍然可以登录,这是容易与窗体身份验证。我想弄清楚如何使用新标识框架做到这一点。

修改

下面是code,最终为我工作:

  app.UseCookieAuthentication(新CookieAuthenticationOptions
{
  AuthenticationType =应用程序,
  LOGINPATH =/帐号/登录,
  CookieDomain =.myapp.com
});


解决方案

在Startup.Auth.cs,你会看到类似这样的:

有关RC:

  app.UseSignInCookies();

这是在RTM取出并用cookie认证的明确的配置取代:

  app.UseCookieAuthentication(新CookieAuthenticationOptions {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LOGINPATH =新PathString(/帐号/登录)
    });

该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身份饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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