FormsAuthentication redirecting to login page on localhost but works as expected when deployed to IIS server. RRS feed

  • Question

  • User994020022 posted


    I'm trying to debug an existing code already deployed to IIS server on my local machine. Authentication works as expected on the IIS server (PROD) but when debugging via Visual Studio  on my local machine I'm getting redirected to login page even with successful/valid login.

    Application uses FormsAuthentication and Cookie to manage access to pages. I've deployed the same local machine code again to another IIS server and Authentication is working fine, so does not seem to be issue of overridding any setting in my local machine while coping/building code. Below is login and web.config code snippet

    Login.aspx code :

    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, UserName.Text, DateTime.Now, DateTime.Now.AddMinutes(60), true, "");
    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
    HttpCookie authCookieLSS = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
    HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(UserName.Text, false));


    <authentication mode="Forms">
    <forms name=".ASPXFORMSAUTH" loginUrl="Login.aspx" defaultUrl="Default.aspx" slidingExpiration="true" timeout="180" protection="None" path="/">

    <location path="Request_Assignment_Home.aspx" >
    <allow users="prodmcc, admin"/>
    <deny users="*"/>

    Few solutions that I've already tried but with no luck:

    • removing  path="/" in <forms> tag.
    • Added tag  domain="localhost" to <forms>
    • changed authCookieLSS.Domain = System.Environment.MachineName; (and Request.Url.Host;)
    • putting response.redirect in block : if (User.Identity.IsAuthenticated) { }

    Some sites also suggested to change 'hosts' system file by adding alias for 'localhost' (e.g. dev.local.com with 2 dots ) but I do not have permission for modifying that file. However don't  think that local debugging should require changing system file.

    Could it be issue that Cookie is not getting created on my local? How can i check that? 

    Been trying to get a fix for this for quite some time now... looking forward for help from you experts here.

    Wednesday, May 20, 2020 11:04 PM

All replies

  • User-719153870 posted

    Hi vishalguleria1981,

    Could it be issue that Cookie is not getting created on my local? How can i check that? 

    Might be, the cookie file is managed by your browser, for example, if you are testing with Chrome, then you shall find the cookie file at:

    C:\Users\<your_username>\AppData\Local\Google\Chrome\User Data\Default\Cookies

    This Cookies file is a SQLite database file, you can go to SQLite Online to open and browse this file:

    Then, run below query in your case:

    SELECT * FROM cookies where name LIKE '%.ASPXFORMSAUTH%';

    Or if you have created this record before, try run delete command below and run your app again to reproduce this issue and then browse this Cookies file again see if this run creates the cookie correclty.

    delete from cookies where name LIKE '%.ASPXFORMSAUTH%';

    Otherwise, you might need to provide all the necessary code related to this issue see if we can reproduce this issue and fix it.

    Best Regard,

    Yang Shen

    Thursday, May 21, 2020 8:15 AM