Shawn Mclean
Shawn Mclean

Reputation: 57469

Sharing asp.net authentication on different apps on different sub-domains

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?

Upvotes: 2

Views: 2078

Answers (2)

Hawxby
Hawxby

Reputation: 2804

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

Upvotes: 2

Michael Grassman
Michael Grassman

Reputation: 1935

in the form tag add

domain=".test.com"

Upvotes: 1

Related Questions