Reputation: 9963
I have 3 mvc4 sites. Site 1 'www.mydomain.com' is a marketing site that allows a user to create an account.
Site 2 'https://businessnamewhatever.mydoman.com' is used for the business to log in and use the available features.
Site 3 WebApi project 'https://api.mydomain.com'
After creating an account within the marketing site (account create via calling webapi) I want to redirect them to 2nd site automatically logging them in.
Both of the sites have forms authentication setup and both use theirown cookie names set within the web.config authentication section
Within my marketing site after calling the api I need to set the auth cookie that will allow the user to automatically log into site 2
I thought it would be just a case of using from within my marketing site
FormsAuthentication.SetAuthCookie(userName, true,"the name of my cookie on site 2");
My 2nd idea was to do a dirty redirect like
var url = string.Format("https://{0}.mydomain.com/account/sign-in?userName={1}&password={2}", model.BusinessName, model.BusinessName, model.Password);
return Redirect(url);
However the redirect never happens. Looking in the network tab I can see the response and if I click on it I am redirected to the site correctly.
Is there a better way to be doing this?
Update
SORRY! I forgot to mention I have a 3rd application working as my API
I have updated all of the web.config as suggested by Kenneth. adding a the same machine key and domain name with authentication settings
After I have called the create user method within the marketing site should I be trying to set the cookie there or should I be doing something else?
Upvotes: 1
Views: 461
Reputation: 8387
Firstly, I'm assuming both products are on separate domains (otherwise you can refer to @Kenneth's answer), and you can make changes to the source code of both sites.
If a validation error occurs (e.g. timeout, or invalid parameters) then the business site should redirect to a predefined URL on the marketing site.
Upvotes: 1
Reputation: 5261
If the 2 sites share a root domain, IE site1.yourdomain.com and site2.yourdomain.com, you should be able to set the machinekey and shared domain in order to allow both sites to access the auth ticket.
Details here. http://msdn.microsoft.com/en-us/library/eb0zx8fc.aspx
Upvotes: 1