Reputation: 82297
While playing around with the global.asax.cs
file I attached some code inside of
protected void Session_Start(object sender, EventArgs e)
{
}
and then started to notice that Session_Start
was being called at every request when using chrome. When using firefox, this was not the case and it was only called once. What could be causing this?
To note, this is only on my dev machine. I compile and run the code, open firefox, browse to http://localhost:63893/
and it hits Session_Start
. While browsing in firefox it only hits Session_Start
once.
When I open chrome and browse to http://localhost:63893/
it hits Session_Start
. Then I enter my login data and hit login, and it hits Session_Start
another time, and then it hits Session_Start
another time while loading the get request for the next page. I used a counter to see, and in fact 3 unique sessions were created during that time.
I know that there are some sources which state that a Session is abandoned when no value is stored in it. That would be a fine explanation here for me, but it is not the case. I disproved this from two methods.
Method 1:
protected void Session_End(){} /*breakpoint*/
Never fired, and I can confirm that the old sessions are still present.
Method 2:
Used Session["KeepAlive"] = true;
inside of Session_Start
to see if that would prevent _Start
from being called but it did not. _End
was still not called.
What is so different between the two or what have I done wrong?
Upvotes: 3
Views: 2733
Reputation: 82297
Thanks for all the help in comments. We actually resolved this in chat and through a link to a blog post: http://tobiefysh.blogspot.co.uk/2010/12/chrome-is-eating-my-session-varibles-or.html
It explains that there was a 302 response when trying to get to favicon.ico
. Basically, chrome is requesting favicon.ico, it is hitting the RegisterRoutes
method and making it into the Session_Start
method which creates excessive Sessions.
The reason it makes it all the way to Session_Start
is because google chrome does not send cookies with favicon requests. So, to all those who though it was a cookie issue: you were right.
Pretty simple fix for all the annoyance, just added this to my RegisterRoutes
method
routes.IgnoreRoute("favicon.ico");
Now google no longer gets a session every time they want my icon.
Upvotes: 6