Session values lost when any exception occurs

Challenge

If you’ve stored some values in session and your session values getting lost when any exception occurs. Then this article may provide you hint to solve it.

Solution

In my case the reason was as below:
Basically I was creating a directory under my web root directory and when any exception occurred I was deleting that directory. And that was the main reason for losing my session values.
So, Now I am creating/deleting directory outside my web root directory and problem is solved!
And deepest reason is Application Restart – Whenever any directory gets created/deleted under web root ASP.NET restarts the application pool. To read more about ASP.NET Application restart read my blog post.
Happy Coding! 🙂

directory