简体   繁体   中英

I can't get authenticated using Forms Authentication with common login

I'm trying to authenticated two applications using the same login form url, all the applications are in the same domain but in different web servers. So, if I put all the applications in the same web sever works perfectly, but in different servers does not work. I've configured the web config of the two applications that need authentication, here is my code.

Both applications has the same in the web.config file

<forms enableCrossAppRedirects="true" cookieless="UseCookies" loginUrl="http://localhost:90/" />
<machineKey  validationKey="[value]" decryptionKey="[value]" validation="SHA1"/>

My login website controller code:

[HttpPost]
public void Index(string userName, string password)
{
    var cookie = FormsAuthentication.GetAuthCookie(userName, false);
    var url = Request.QueryString["ReturnUrl"];

    //Here I will check the user credentials
    if (userName == "usernameX" && password == "passwordX")
    {
        Response.Redirect(String.Format("{0}?{1}={2}",
        Request.QueryString["ReturnUrl"],
        FormsAuthentication.FormsCookieName,
        cookie.Value));
    }
}

Well, I found the answer. I need to put the machine key and validation key in the login page App, that in my case is another application that function like a common loin page for all the applications. And is necessarily specify the domain in which your are going to share the cookie.

 <forms enableCrossAppRedirects="true" cookieless="UseCookies" loginUrl="http://localhost:90/" domain="mydomain.com"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM