We have two ASP aplications running at the same server (in different subdomains), the first one is a Web Forms aplications (I'll call that App A) and the new one a APS.NET MVC aplication (App B).
The App B need to login in the App A restrited area, I saw in the web about sharing cookies in differents applications, but, in my tests, the redirect works, however the cookies can't be found.
Here's how I send cookies in App B:
var log = auth.GetLogin(user, password, Request.ServerVariables["REMOTE_ADDR"], 1);
if (!log.isPasswordValid)
throw new Exception("user or password incorrect!");
FormsAuthentication.SetAuthCookie(user, false);
And, in the App A, here's how I try to get the cookie:
if(HttpContext.Current.Request.Cookies["ASPXAUTH"] != null)
{
var user = httpContext.Current.Request.Cookies["ASPXAUTH"].Value;
Session["LoginUser"] = user;
}
the ASPXAUTH key is the authentication in Web.Config
<authentication mode="Forms">
<forms loginUrl="/Login/Acess" enableCrossAppRedirects="true" path="/" name=".ASPXAUTHX" domain="dev.com.br" protection="All" />
</authentication>
The Wrost part is that I can't even debug the application to check values :(
Can someone help me ?
EDIT 1
I followed those instructions in this page and, sometime I've getting the redirect "correctly", but with no sessions at all.
Here's the code (in the App a here I recive the cookies):
if (HttpContext.Current.Request.IsAuthenticated)
{
for (int i = 0; i < HttpContext.Current.User.Identity.Name.Length; i++)
{
userId += userId = HttpContext.Current.User.Identity.Name[i].ToString();
}
}
Sometimes the userId doesn't came, and it throws a exception in the Length part (the HttpContext.Current.User.Identity.Name comes null).
My thoughts is that the ApplicationName App A is not the same as the App B, but I tried to change in this page and it didn't work.
Can somebody help me?