Click here to Skip to main content
11,492,279 members (65,311 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ASP.NET , +
Dear Friends,

am facing problem with session timeout.

I have created a web application in asp.net 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.
Posted 27-Jan-13 5:52am
Comments
Muthuraja Irullandi at 27-Jan-13 10:59am
   
Hi,
What is your timeout setting in config file?
Zoltán Zörgő at 27-Jan-13 11:41am
   
What authentication are you using? ASP.NET Form authentication or you made something on your own?
Trics071 at 28-Jan-13 5:14am
   
Just increase Session Time Out value in Web Config File. Default Value is 20
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please check the session exists or not on pageload

if(Session["UserName"]=="")
{
Response.redirect("Loginpage.aspx");
}


Thanks
  Permalink  
Comments
Marcus Kramer at 29-Jan-13 11:02am
   
+5.
AshishChaudha at 30-Jan-13 1:24am
   
Thanks Marcus
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

HI,

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
            }
            else
            {
                //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.

1.
Session.Timeout = 540;

OR

2.
<system.web>
 
.......
 
<sessionstate timeout="1440"></sessionstate>
 
</system.web>


Thanks
  Permalink  
v4
Comments
Marcus Kramer at 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.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 455
1 Maciej Los 306
2 Sascha Lefèvre 265
3 Andy Lanng 235
4 KarstenK 220
0 Sergey Alexandrovich Kryukov 9,943
1 OriginalGriff 8,610
2 Sascha Lefèvre 3,609
3 Maciej Los 3,372
4 Richard Deeming 2,440


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100