【发布时间】:2013-10-03 18:32:47
【问题描述】:
对于表单身份验证,我在 web.config 中使用了这个(注意域属性):
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" name=".ASPXAUTH" protection="Validation" path="/" domain=".myserver.dev" />
</authentication>
如何为 Mvc 5 中的新 ASP.NET 身份框架配置跨子域的单点登录?
更多信息:
我正在创建一个多租户应用程序。每个客户端都在一个子域中:
client1.myapp.com
client2.myapp.com
我希望用户能够登录到client1.myapp.com,然后转到client2.myapp.com 并且仍然可以登录。这很容易通过表单身份验证。我正试图弄清楚如何使用新的身份框架来做到这一点。
编辑
这是最终对我有用的代码:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Application",
LoginPath = "/Account/Login",
CookieDomain = ".myapp.com"
});
【问题讨论】:
-
您是为所有子域提供一个应用程序,还是为每个子域提供一个应用程序?我有第二个选项,但它不起作用:(
-
我们可以从App的其他地方访问
CookieAuthenticationOptions吗? IE。我们可以在HomeController中更改它以设置会话超时吗? -
我只是想告诉您,如果您在 localhost 上尝试此操作,它可能不起作用。我花了两个小时来确定为什么它不起作用,但我做不到。然后我只想在服务器上尝试这个答案,它就成功了。
标签: c# authentication forms-authentication asp.net-identity