User994020022 posted
Hi,
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.Cookies.Add(authCookieLSS);
HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(UserName.Text, false));
web.config:
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="Login.aspx" defaultUrl="Default.aspx" slidingExpiration="true" timeout="180" protection="None" path="/">
</forms>
</authentication>
<location path="Request_Assignment_Home.aspx" >
<system.web>
<authorization>
<allow users="prodmcc, admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
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.