I am facing a problem in ASP.NET. I have a dropdownlist in Master Page and I am accessing it in a library outside the UI project using the below code :
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
return page.Master.FindControl("MyDdl") as DropDownList;
}
This code works fine normally. But sometimes if I remain inactive for 15 to 20 minutes and then cause a postback (e.g. Click button, change menu etc..) Master property of the page becomes null. i.e. page.Master
starts returning null. Then I press F5 to refresh the page and it starts working again. I also searched google but did not find any relative answer. Can anyone guide me what is going on here?
You are experiencing session timeout, your session has ended. There are two places where you can configure session.
First inside your web application web.config like this:
<configuration>
<system.web>
<sessionState timeout="30"></sessionState>
</system.web>
</configuration>
or second using IIS manager:
Go to tab with main properties for your application, double click "Session state", at the bottom of the tab there is "Time-out (in minutes)". Also there are other options to change session state storage.
There is also option to check session state using code. Please take a look at this article: http://www.codeproject.com/Articles/227382/Alert-Session-Time-out-in-ASP-Net
Happy coding!