BACKGROUND:
I’m using two MVC3 websites for mixed mode authentication. I’m authenticating a person using windows authentication in Site1, and then forwarding that person onto Site2 which uses Forms authentication. My solution was to gather user information in site1 once the user is authenticated via windows auth. I would then write this info to a cookie, and then redirect to Site 2. Site 2 would then use the info found in the cookie to automatically log in the user using Forms Auth. Both applications are in the same domain and should be able to share cookies, however the cookie isn’t available after the redirect until the page is refreshed or by clicking on a link in the site (visiting a 2nd page).
Anyway, here’s my problem. I create the cookie and then forward the user to Site2 from Site1.
...{cookie created here and added to response}...
HttpContext.Response.Redirect("http://site2.mydomain.com")
When I do this, there isn’t a cookie in the request. However, once on the home page of Site2, I can hit refresh, and then my cookie is part of the request and my authentication works.
I need my Response to write the cookie to the client, then get that cookie added in the request, but it seems to skip that when using Response.Redirect…
UPDATE:
I’ve read that the request will only have cookies included when the cookie exists before the request is made. Since I’m writing the cookie into the response for the request, only subsequent requests will contain the cookie. So, what I need is a way to force a second request, once they get my response from the initial request. So…
User sends request —> response returns with cookie —> force another request (should contain cookie) —> return requested page.
Can I do this using javascript? Can the javascript check the response for a cookie of a certain name, and when found, cause a redirect to the current page?
If you have to force the refresh to get a second request, you could perhaps append a Query String parameter from Site1’s redirect HttpContext.Response.Redirect(“http://site2.mydomain.com?refresh=1”), then in Site2, cause a redirect to the same page sans query string parameter.
That’s not really ideal though. Could you put that cookie information into a query string for a one off authentication URL that then stores a new cookie and redirects to Site2’s homepage?