Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session variable trounced by Chrome and FF

In my asp.net web application on page load I grab the current page url and store it in a session variable to track which page the user is on so they can return to it if they enter an admin area, do some navigating around etc. They can then click the return button and will be taken to the page they were on before entering the admin.

This all works in IE8; however in FF and Chrome when in the admin the return link redirects to the custom 404 page I have for the web app.

For testing purposes I added the code I wrote below in with my page load event:

Response.Write((string)Session["navurl"]);// displays "http://somedomain.com/customerror/default.aspx"
Session["navurl"] = currentUrl;//ex. currentUrl = "http://somedomain.com/contact/"
Response.Write((string)Session["navurl"]);//ex. currentUrl = "http://somedomain.com/contact/"

Again this works without a problem in IE, but in FF and Chrome on page load the session variable displays the 404 page link and after setting it displays the correct link. I used fiddler to see what was going on and Chrome is throwing a 404 in the GET header for the favicon.ico file, which I am not using in this web app.

I added the faviocon file and the link in the head of the site.master file and Chrome and FF now work fine; I'm still not sure why this is happening. Anyone have an ideas why or how my Session variable is getting overwritten by Chrome or FF?

As a side note I have stepped thru the process debugging and currentUrl is the proper url.

like image 684
Mark Avatar asked Feb 04 '11 23:02

Mark


1 Answers

Well, if you are using the .NET handler to serve all pages (ie. all file extensions), then it makes sense that when your browser will make a request for favicon.ico (google to understand what this is), the server fails to find it, and it redirects to a 404. Which in turn modifies the Session variable as "the last page served" : 404.

Now when you render you admin page, and query the Session for "the last page served" what do you get ? "404".

I'd suggest checking the URL to see if it reffers to a user-navigationable page before storing it in session

if (IsAUserPage(currentUrl)
  Session["navurl"] = currentUrl;
like image 64
Radu094 Avatar answered Nov 04 '22 04:11

Radu094