Using ASP.NET Tracing to Troubleshoot Session Loss

Hi Again,

This post is an Add-on to my previous blog. Yesterday I got my 15th Session loss case. This is the second time the same issue is coming to me and it took hardly 15 minutes for me to solve the same. But for the first time when we were troubleshooting the issue it took more than 8 hours to figure out what’s happening. Ok let’s start.

Some Session variables are lost while moving between pages.

Session variables are suddenly lost when we move from one page to another. That too only some specific session variables. There is no application domain restart, issue happens to all users from all machines and is consistently reproducible.

This is a little tricky scenario where we end up using all our troubleshooting skills and still end up at the “No Where” Side. Happy

Customer had created a simple ASP.Net application to reproduce the issue. There were only two pages, In Page 1 he was setting some Session variables .On click of  "Move to Page2" we are redirected to page 2 where we print the Session variables. Page 2 contains an <Img > tag whose source is pointed to an image which doesn’t exist at all. So when we access the page we will see a cross sign.

Page 1


Session["Value1"] = "Ani";

Session["Value2"] = "Menon";



Page 2


Label1.Text = "First Value : " + Session["Value1"].ToString();

Label2.Text = "Second Value : " + Session["Value2"].ToString();



Now when click on “Back to Page 1” button, we are redirected to page 1, where we are trying to print the Session Values and Surprisingly one Session variable is lost.


There is no other code in these pages and in Global.asax.cs (No session.clear() or Session.abandon etc).

Now the toughest part. How to troubleshoot this?? At wits end !!!! .Here comes the power of ASP.Net tracing. Go ahead and enable tracing in Web.config file.

<trace enabled="true"/>

We tried browsing the pages again and checked for the sequence of events happening and found something interesting.


See the figure above. We can see that there is a GET request for Error.aspx {from where this request came from Worried!!}.

We checked the Virtual directory settings in IIS and found that under Custom Errors Tab customer has set a redirection to a custom Error Page for 404. File not found.


(For demo purposes I am just redirecting to an Error page within the same directory as of the application, but in a complex real time scenario, this won’t be the case.)

We checked the Error.aspx.cs page and found that the Session value was set to “null” based on some condition.

Session["Value1"] = null;

We removed the custom error page and that fixed the issue. Now the interesting thing is that if we have set a custom error page the 404 redirection won’t get logged in IIS logs or tools like fiddler ( as it is already been handled.

Fiddler trace with Custom Error Redirection


Fiddler trace without Custom Error Redirection


So ultimately what's happening was , when we are redirected to Page2.apsx a 404 is generated for <IMG>. This is handled by the custom Error page settings in IIS , which redirects the request to Error.aspx which which was clearing out the Session variable.Cool

Hope this helps…Until Next time... Bye Bye