I have 2 applications. One on asp.net webforms main.test.com
which should provide authentication, user logs in and I can use the cookie to authenticate on my asp.net mvc app located at myApp.test.com
.
All I'd like to do is able to access the cookie so I can get the userId that was stored in it using the FormsAuthentication
.
They use normal authentication provided by microsoft;
<authentication mode=开发者_运维问答"Forms">
<forms domain="test.com" loginUrl="Default.aspx" protection="All" path="/" requireSSL="false" timeout="45" name=".ASPXAUTH" slidingExpiration="true" defaultUrl="Default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
</authentication>
This cookie should be accessible to any submain on test.com right?
Make sure you set your machine keys in each application so they can each decrypt each others data. http://msdn.microsoft.com/en-us/library/ff649308.aspx
Then make sure you have set your cookie name and path the same in each. Job done, an auth ticket generated in either application should span them both http://msdn.microsoft.com/en-us/library/ff647070.aspx
Edit: Forgot a bit:
In your web config also set the domain attribute of the httpCookies node to test.com
in the form tag add
domain=".test.com"
精彩评论