Application control is redirecting to the login page on every server request

anup_daware

Newcomer
Joined
Mar 13, 2006
Messages
24
Location
India
Hi All,[FONT=&quot][/FONT]
I am facing this very weird issue, for every server request my control is redirecting to the login page and again coming back to the actual page from where the request was initiated when I set my custom Remember be cookie on the login page. Following are the details:[FONT=&quot][/FONT]
1.[FONT=&quot] [/FONT]Authentication mode is ‘Forms’[FONT=&quot][/FONT]
2.[FONT=&quot] [/FONT]This issue is reproducible only in deployed applications, I found this using my trace and remote debugging[FONT=&quot][/FONT]
3.[FONT=&quot] [/FONT]This issue occurs only when user selects the ‘Remember Me’ option at the time of login, then I set the custom cookie for storing the user info. (inbuilt Remember Me of login control is not used as I need the fixed expiration and not the sliding one)[FONT=&quot][/FONT]
4.[FONT=&quot] [/FONT]It is also observed that issue occurs only when I create a msi and deploy it, if I just take the code and publish it on server the application works fine and there are no unnecessary redirections to login[FONT=&quot][/FONT]
5.[FONT=&quot] [/FONT]Application is Ajax enabled[FONT=&quot][/FONT]

[FONT=&quot]//Following is the code where I set the cookie used for remember me:[/FONT][FONT=&quot][/FONT]
[FONT=&quot]2 [/FONT][FONT=&quot]// To store the authentication cookie.[/FONT]
[FONT=&quot]3 [/FONT][FONT=&quot]HttpCookie myTLCookie = new HttpCookie("UserCookie");[/FONT]
[FONT=&quot]4 [/FONT][FONT=&quot]Response.Cookies.Remove("UserCookie");[/FONT]
[FONT=&quot]5 [/FONT][FONT=&quot]//Save username and password in the cookie.[/FONT]
[FONT=&quot]6 [/FONT][FONT=&quot]myTLCookie.Values["Username"] = LoginTyreLink.UserName;[/FONT]
[FONT=&quot]7 [/FONT][FONT=&quot]myTLCookie.Values["Password"] = LoginTyreLink.Password;[/FONT]
[FONT=&quot]8 [/FONT][FONT=&quot]myTLCookie.Values["LanguageCodeForMegaFleet"] = (((DropDownList)LoginTyreLink.FindControl("dropDownListLanguage")).SelectedItem.Value).Substring(6, 3);[/FONT]
[FONT=&quot]9 [/FONT][FONT=&quot]myTLCookie.Values["UICulture"] = (((DropDownList)LoginTyreLink.FindControl("dropDownListLanguage")).SelectedItem.Value).Substring(0, 5);[/FONT]
[FONT=&quot]10 [/FONT][FONT=&quot]myTLCookie.Values["Culture"] = (((DropDownList)LoginTyreLink.FindControl("dropDownListLanguage")).SelectedItem.Value).Substring(0, 5);[/FONT]
[FONT=&quot]11 [/FONT][FONT=&quot]myTLCookie.Values["LanguageForTyreDetails"] = (((DropDownList)LoginTyreLink.FindControl("dropDownListLanguage")).SelectedItem.Value).Substring(10);[/FONT]
[FONT=&quot]12 [/FONT][FONT=&quot]myTLCookie.Values["ClientOffsetTime"] = SessionManager.CurrentUser.GetTimezoneOffset().ToString();[/FONT]
[FONT=&quot]13 [/FONT][FONT=&quot][/FONT]
[FONT=&quot]14 [/FONT][FONT=&quot]// Read the expiry period from the session and set the cookie life time of the cookie accordingly. [/FONT]
[FONT=&quot]15 [/FONT][FONT=&quot]// Note that the client local time is used to decide the cookie expiry time[/FONT]
[FONT=&quot]16 [/FONT][FONT=&quot]myTLCookie.Expires = Time.AddHours(double.Parse(ConfigurationManager.AppSettings.Get("SessionTimeout").ToString()));[/FONT]
[FONT=&quot]17 [/FONT][FONT=&quot]try[/FONT]
[FONT=&quot]18 [/FONT][FONT=&quot]{[/FONT]
[FONT=&quot]19 [/FONT][FONT=&quot]HttpCookie encodedCookie = Utilities.HttpSecureCookie.Encode(myTLCookie);[/FONT]
[FONT=&quot]20 [/FONT][FONT=&quot] Response.Cookies.Add(encodedCookie);[/FONT]
[FONT=&quot]21 [/FONT][FONT=&quot]}[/FONT]
[FONT=&quot]22 [/FONT][FONT=&quot]catch (Exception exp)[/FONT]
[FONT=&quot]23 [/FONT][FONT=&quot]{[/FONT]
[FONT=&quot]24 [/FONT][FONT=&quot]HandleException(exp);[/FONT]
[FONT=&quot]25 [/FONT][FONT=&quot]}[/FONT]
[FONT=&quot]26 [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] //Following the is the code that reads the Remember Me cookie at the time of load of login page and sets the authentication cookie:[/FONT]
[FONT=&quot]2 [/FONT][FONT=&quot]if (Request.Cookies.Get("UserCookie") != null)[/FONT]
[FONT=&quot]3 {[/FONT]
[FONT=&quot]4 HttpCookie cookie = Request.Cookies.Get("UserCookie");[/FONT]
[FONT=&quot]5 HttpCookie decodedCookie = Utilities.HttpSecureCookie.Decode(cookie);[/FONT]
[FONT=&quot]6 if (decodedCookie.Values["Username"] != null && decodedCookie.Values["Password"] != null)[/FONT]
[FONT=&quot]7 {[/FONT]
[FONT=&quot]8 if (ValidateUser(decodedCookie.Values["Username"].ToString(), decodedCookie.Values["Password"].ToString(),0.0))[/FONT]
[FONT=&quot]9 {[/FONT]
[FONT=&quot]10 FormsAuthentication.SetAuthCookie(decodedCookie.Values["Username"].ToString(), false);[/FONT]
[FONT=&quot]11 Response.Redirect(LoginControl.DestinationPageUrl);[/FONT]
[FONT=&quot]12 }[/FONT]
[FONT=&quot]13 }[/FONT]
[FONT=&quot]14 }[/FONT]

While I am probably almost certain that the issue is with Forms Authentication and Cookies, I am not able figure out what it could be. Please help.[FONT=&quot][/FONT]
Thanks,[FONT=&quot][/FONT]
Anup[FONT=&quot][/FONT]
[FONT=&quot] [/FONT]
 
Back
Top