Click here to Skip to main content
15,668,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

am facing problem with session timeout.

I have created a web application in with C# and database as Sql2005. its works fine.

When the application is idle, it shows the session error.
for this application, first page is login page.

it shows the errror

lbluser.Text = Session["UserName"].ToString();

This code is in master page. this is used for displaying username with label

for example

Welcome Mr. Developer

but when the progam is idle , when i click some links in this application it shows Session Error.

Please help me, how to solve.

Thanks in Advance.
Muthuraja Irullandi 27-Jan-13 10:59am    
What is your timeout setting in config file?
Zoltán Zörgő 27-Jan-13 11:41am    
What authentication are you using? ASP.NET Form authentication or you made something on your own?
Trics071 28-Jan-13 5:14am    
Just increase Session Time Out value in Web Config File. Default Value is 20

Please check the session exists or not on pageload


Share this answer
fjdiewornncalwe 29-Jan-13 11:02am    
AshishChaudha 30-Jan-13 1:24am    
Thanks Marcus
Share this answer
fjdiewornncalwe 29-Jan-13 11:02am    
Increasing the timeout will in no way fix the problem. It will just cause the issue to appear more infrequently.

You can check the session existance in the pageload and then perform your operations:

if (!string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
                //Redirect to the respective page
                //Redirect to the login page

Here IsNullOrEmpty checks for the null as well as "" values simultaneously.

There is another way:

Increase the session timeout value.

Session.Timeout = 540;




<sessionstate timeout="1440"></sessionstate>


Share this answer
fjdiewornncalwe 29-Jan-13 11:03am    
My 1. Just reposting the existing answers in your own way does not make it a new answer. Still a repost.
[no name] 30-Jan-13 1:30am    
Thanks but in the above answers the content and the use are missing. You should be writing the answers in such a way that your code should meet the maximum efficiency. I had added the answers with the proper description inorder to make the enquirer be a good coder. I too hate to repost any answers. But thankd for your concern dear...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900