mvc3 forms authentication across sub-domains in single application

删除回忆录丶 提交于 2019-12-11 16:14:41

问题


Similar to this question: Single Sign-on - MVC3 and Webforms

I have a MVC3 application with custom routing that takes the first part of the sub-domain URL and uses it as a variable. So, for example, test1.mydomain.com gives my controllers the variable subdomain a value of test1. If we type in test2.mydomain.com, then the controllers receive "test2".

The problem is with authentication (using built-in forms auth). If I log on while on test1.mydomain.com and then navigate to test2.mydomain.com, it doesn't persist the the log on to that subdomain. Of course if I navigate back, it shows that I'm logged in.

I've tried the following two solutions, but they didn't work: http://www.codeproject.com/KB/aspnet/SingleSignon.aspx Forms Authentication across Sub-Domains

I've added a Machine Key to the app, though I'm not sure if this was necessary. NOTE: I'm still on the dev box so the domain is coming up localhost:2510. So, for example, my subdomains are test1.localhost:2510 and test2.localhost:2510. I've tried to manually set the auth cookie domain to "localhost" and that doesn't work. I'm telling you this in case the problem is that I'm running from "localhost". I'm in the process of testing it under a different binding (mysite.com). I'll update if that works. For now though, does anyone have any ideas?


回答1:


After I created the mysite.com domain name locally (iis binding) and surfing to my application there, I found that the solution given on http://www.codeproject.com/KB/aspnet/SingleSignon.aspx works perfectly. Shoot me a msg if you need any more clarification. Localhost can't be used when trying to persist authentication between sub-domain on a single MVC3 application.



来源:https://stackoverflow.com/questions/7033292/mvc3-forms-authentication-across-sub-domains-in-single-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!