By default our websites session timeout is 20 mins after that session will gets expire suppose if we want to set our custom timeout in our applications we can set it in different ways (web.config, global.asax and in IIS)
Check below methods to set session timeout in web.config, global.asax and in iis
In Web.config file we can set session timeout like as shown below
<configuration>
<system.web>
<sessionstate mode="InProc" timeout="60">
</sessionstate>
</system.web>
</configuration>
reference
Asp.net set session timeout.. :)[
^]
Updated
if session is already expired then you can not convert it into string from .toString()
try this..
if(Session["username"]!=null || Session["username"]!="")
{
lblUserName.Text = Convert.ToString(Session["username"]);
}
else
{
}