473,815 Members | 3,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session Time out if browser is idle for 5 minutes

AnuSumesh
96 New Member
Hi All,

We r developing web application in asp.net using c#. we r using IIS7.0 and windows vista for development.
I m using windows authentication and "local Sytem" Identity.
I want that if user is not accessing site for 5 minutes(means browser is idle for 5 min) , after 5 min. when user clicks on any link, his session should be expired and he has to provide login credentials again.

I have tried using
<sessionState cookieless="Fal se" mode="InProc timeout="5" />

in web.config file but its not working.

Please help me in this issue.

Thanks
Anu
May 5 '08 #1
13 12360
Plater
7,872 Recognized Expert Expert
Hmm, have you tried going to the IIS config and changing the value there?

Also, do you validate the Session on every page load?
May 5 '08 #2
AnuSumesh
96 New Member
Hi

Thanks for reply.

No i dont know much abt aspx 'n' .net. How to validate the session?

Regards
Anu


Hmm, have you tried going to the IIS config and changing the value there?
.
Also, do you validate the Session on every page load?
May 6 '08 #3
Plater
7,872 Recognized Expert Expert
Well I mean, you want the session to timeout. so you must be doing something with the Session object? Like holding onto a login name or something.
If you check to make sure the user is "logged in" at every page, when the session timesout and gets cleared, the user will no longer be "logged in" and you should be able to detect that.
May 6 '08 #4
Frinavale
9,735 Recognized Expert Moderator Expert
Hi All,

We r developing web application in asp.net using c#. we r using IIS7.0 and windows vista for development.
I m using windows authentication and "local Sytem" Identity.
I want that if user is not accessing site for 5 minutes(means browser is idle for 5 min) , after 5 min. when user clicks on any link, his session should be expired and he has to provide login credentials again.

I have tried using
<sessionState cookieless="Fal se" mode="InProc timeout="5" />

in web.config file but its not working.

Please help me in this issue.

Thanks
Anu
There's no reason to believe that the session hasn't timed out.
In your PageLoad you should be checking if the user has been logged out or not.

I'm assuming that when the user logs into your website a session variable is created for that user to indicate that they are logged in. When your session times out this variable will no longer be accessible...th erefore in your PageLoad code you should check if this variable is null or nothing and if so redirect the user to the login page. This will prevent the button or link from being executed.

-Frinny
May 6 '08 #5
AnuSumesh
96 New Member
Thanks for Reply.

I m doing same as u told but facing some problems:
If user tries to access any other page directly then he is redirected to default page(we r using basic authentication) .
i m using following code on page_load method of master page
Expand|Select|Wrap|Line Numbers
  1. string username="";
  2. if (Session["Username"] != null)
  3.      username = Session["Username"].ToString();
  4.  
  5.      if (username == "")
  6.      { 
  7.           string url = Application["URL"].ToString();
  8.           Response.Redirect(url); 
  9.      }
  10.      if(Context.Session.IsNewSession)
  11.      { 
  12.           if(Session["Username"] == null)
  13.           { 
  14.           System.Web.HttpContext.Current.Response.Redirect("~/admin/logoff.aspx");
  15.           Session.Abandon();
  16.           }
  17.      }
  18.      else
  19.      {
  20.           //load page
  21.      }
  22.  
Here one problem is when i m closing window and opens a new window and trying to access any page directly then user is redirected to logoff page rather than to default page.

If first time i m trying to access page directly then it is redirected to default page but not after accessing site regularly

Session["username"] is set in default page.

One more issue is :
I m using global.asax file 'n' its code is as follows:
Session_start() is called everytime when i click on anylink on my site.

can u please help me?

Regards
Anu


There's no reason to believe that the session hasn't timed out.
In your PageLoad you should be checking if the user has been logged out or not.

I'm assuming that when the user logs into your website a session variable is created for that user to indicate that they are logged in. When your session times out this variable will no longer be accessible...th erefore in your PageLoad code you should check if this variable is null or nothing and if so redirect the user to the login page. This will prevent the button or link from being executed.

-Frinny
May 7 '08 #6
Frinavale
9,735 Recognized Expert Moderator Expert
Thanks for Reply.

I m doing same as u told but facing some problems:
If user tries to access any other page directly then he is redirected to default page(we r using basic authentication) .
i m using following code on page_load method of master page
Expand|Select|Wrap|Line Numbers
  1. string username="";
  2. if (Session["Username"] != null)
  3.      username = Session["Username"].ToString();
  4.  
  5.      if (username == "")
  6.      { 
  7.           string url = Application["URL"].ToString();
  8.           Response.Redirect(url); 
  9.      }
  10.      if(Context.Session.IsNewSession)
  11.      { 
  12.           if(Session["Username"] == null)
  13.           { 
  14.           System.Web.HttpContext.Current.Response.Redirect("~/admin/logoff.aspx");
  15.           Session.Abandon();
  16.           }
  17.      }
  18.      else
  19.      {
  20.           //load page
  21.      }
  22.  
Here one problem is when i m closing window and opens a new window and trying to access any page directly then user is redirected to logoff page rather than to default page.

If first time i m trying to access page directly then it is redirected to default page but not after accessing site regularly

Session["username"] is set in default page.

One more issue is :
I m using global.asax file 'n' its code is as follows:
Session_start() is called everytime when i click on anylink on my site.

can u please help me?

Regards
Anu
First of all you are specifically link them to the Log Out page in your redirect.
Why are you doing this? If their session doesn't exist then they are logged out are they not? Shouldn't you redirect them to your Log In page instead?
You should consider putting any log-out clean up in your Session_End event instead of redirecting your user to the Log Out Page.

I'm really note sure why Session_Start is called every time you click on a button in your site....unless you are not storing anything in session and then you are trying to access it to tell if the user is logged in.

Please post your code for your Log In Button Click so that I can see what you are doing.


-Frinny
May 7 '08 #7
AnuSumesh
96 New Member
Hi,

I m very greatful to you for responding my questions.
I have lot of queries as i m new to .net.

1.
i m not using any login form. i m using basic authentication which by default asks for username and password. After authentication user is redirected to default.aspx page 'n' in that page_load i m setting
session["username"]=loginusername.
'n' this is the reason of using logoff.aspx page.

code for global.asax file is :

<%@ Application Language="C#" %>
<script runat="server">
void Application_Sta rt(object sender, EventArgs e)
{
// Code that runs on application startup

}

void Application_End (object sender, EventArgs e)
{
// Code that runs on application shutdown
Application["URL"] = null;
Application.Rem oveAll();
Application.Cle ar();
}

void Application_Err or(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(o bject sender, EventArgs e)
{
Application.Loc k();


string url = "";
//code to form the url
Application["URL"] = url;

Application.UnL ock();
}

void Session_End(obj ect sender, EventArgs e)
{
Session.Clear() ;
Session.RemoveA ll();
Request.Cookies .Clear();
Request.Headers .Clear();
Session.Abandon ();
}

</script>

code for default.aspx.cs page is:

protected void Page_Load(objec t sender, EventArgs e)
{
string UserName = User.Identity.N ame;//Request.LogonUs erIdentity.Name ;
Session["Username"] = UserName;
Response.Redire ct("items.aspx? nid=Start");
}

and the code that i sent u earlier is for master page.
When sesion expires, session_end is not getting called at all.
So i m using session.abondon () in logoff.aspx page.

2. i m using basic authentication, so whenever after logoff i m opening site in same browser its not asking for login user 'n' password. it is directly opening the site.
Is there solution for this also?

3. i m providing facility to user to chenge the server date 'n' time and also shutdown/restart the server through webui.
When i tested my code locally via asp development, then its working fine. But after deploying the web app, when i m accessing site via https://webapp then its throwing exception "Privilege not held".
Even i haveenabled privileges for the user.
Deployment scenario is :
Basic authentication 'n' identity is "LocalSyste m".
Any help in this issue?

Thanks a lot.
Regards,
Anu


First of all you are specifically link them to the Log Out page in your redirect.
Why are you doing this? If their session doesn't exist then they are logged out are they not? Shouldn't you redirect them to your Log In page instead?
You should consider putting any log-out clean up in your Session_End event instead of redirecting your user to the Log Out Page.

I'm really note sure why Session_Start is called every time you click on a button in your site....unless you are not storing anything in session and then you are trying to access it to tell if the user is logged in.

Please post your code for your Log In Button Click so that I can see what you are doing.


-Frinny
May 8 '08 #8
Frinavale
9,735 Recognized Expert Moderator Expert
Hi,

I m very greatful to you for responding my questions.
I have lot of queries as i m new to .net.

1.
i m not using any login form. i m using basic authentication which by default asks for username and password. After authentication user is redirected to default.aspx page 'n' in that page_load i m setting
session["username"]=loginusername.
'n' this is the reason of using logoff.aspx page.

code for global.asax file is :

<%@ Application Language="C#" %>
<script runat="server">
void Application_Sta rt(object sender, EventArgs e)
{
// Code that runs on application startup

}

void Application_End (object sender, EventArgs e)
{
// Code that runs on application shutdown
Application["URL"] = null;
Application.Rem oveAll();
Application.Cle ar();
}

void Application_Err or(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(o bject sender, EventArgs e)
{
Application.Loc k();


string url = "";
//code to form the url
Application["URL"] = url;

Application.UnL ock();
}

void Session_End(obj ect sender, EventArgs e)
{
Session.Clear() ;
Session.RemoveA ll();
Request.Cookies .Clear();
Request.Headers .Clear();
Session.Abandon ();
}

</script>

code for default.aspx.cs page is:

protected void Page_Load(objec t sender, EventArgs e)
{
string UserName = User.Identity.N ame;//Request.LogonUs erIdentity.Name ;
Session["Username"] = UserName;
Response.Redire ct("items.aspx? nid=Start");
}

and the code that i sent u earlier is for master page.
When sesion expires, session_end is not getting called at all.
So i m using session.abondon () in logoff.aspx page.

2. i m using basic authentication, so whenever after logoff i m opening site in same browser its not asking for login user 'n' password. it is directly opening the site.
Is there solution for this also?


Thanks a lot.
Regards,
Anu
First of all, I'm pretty sure that using Basic Authentication doesn't allow you to log off the user. The only way to "log off" a user is through using Forms Authentication.

Secondly, If I were you, I would consider creating a Log In page that redirects the user to the default page so that you have a clean starting point to your application (so that you don't redirect them to a log off page...I'm still not sure what this log off page does).


The Session_End event is only accessed if your session contains something. If there's nothing in Session this event is not called.

If you don't think that your Session_End is being called (after 5 minutes), then consider outputting a timestamp record to a text file when ever this event is fired to see....Better yet, write a timestamp record to the text file in your Session_Start and your Session_End, then leave for 6 minutes and check this file...

Why are you even storing the User Name in session? You should be able to access the User.Identity.N ame property at all times anyways, so there should be no need to store this information.

It feels like you're mixing 2 Authentication methods (Forms and Windows). I would suggest sticking to one form of authentication.

3. i m providing facility to user to chenge the server date 'n' time and also shutdown/restart the server through webui.
When i tested my code locally via asp development, then its working fine. But after deploying the web app, when i m accessing site via https://webapp then its throwing exception "Privilege not held".
Even i haveenabled privileges for the user.
Deployment scenario is :
Basic authentication 'n' identity is "LocalSyste m".
Any help in this issue?
Allowing a web user to shutdown the server, or change the server's Date/Time is not a good idea. You are probably getting this error because web applications have a Low Trust level, meaning that through these applications you will not be able to do things like shut down or change the date on the server. The DEV server that comes with Visual Studio lets you do things that a real IIS server would never let you do. In order to get this to work on your IIS you will have to give the web application a higher trust level...which is not advisable because you should never trust your web users this much. This could create a huge security hole in your software.

I have no idea how to Log Off a user if you are using Basic Authentication.
I would recommend switching to Forms Authentication if you would like to log of your user.

I would also recommend creating another application (a desktop application that will be run on the server) that allows the system administer of your web server to perform maintenance on your application and your server. I strongly recommend against letting a user from the web do this.

-Frinny
May 8 '08 #9
AnuSumesh
96 New Member
Thanks for reply.
1. I will try using Form Authentication if required.

2. We are preparing Web Application for System Management/Maintenance which requires to provide the facility to change date/time and ahutdown the system. I have alreday given Full(internal) trust level in IIS->webApp->.net trust Levels. But still its giving error "A required Privilege is not held by the client". What can be the problem. In any case i have to solve this issue. B'coz this is our main requirement.

Thanks 'n' Regards,
Anu


First of all, I'm pretty sure that using Basic Authentication doesn't allow you to log off the user. The only way to "log off" a user is through using Forms Authentication.

Secondly, If I were you, I would consider creating a Log In page that redirects the user to the default page so that you have a clean starting point to your application (so that you don't redirect them to a log off page...I'm still not sure what this log off page does).


The Session_End event is only accessed if your session contains something. If there's nothing in Session this event is not called.

If you don't think that your Session_End is being called (after 5 minutes), then consider outputting a timestamp record to a text file when ever this event is fired to see....Better yet, write a timestamp record to the text file in your Session_Start and your Session_End, then leave for 6 minutes and check this file...

Why are you even storing the User Name in session? You should be able to access the User.Identity.N ame property at all times anyways, so there should be no need to store this information.

It feels like you're mixing 2 Authentication methods (Forms and Windows). I would suggest sticking to one form of authentication.


Allowing a web user to shutdown the server, or change the server's Date/Time is not a good idea. You are probably getting this error because web applications have a Low Trust level, meaning that through these applications you will not be able to do things like shut down or change the date on the server. The DEV server that comes with Visual Studio lets you do things that a real IIS server would never let you do. In order to get this to work on your IIS you will have to give the web application a higher trust level...which is not advisable because you should never trust your web users this much. This could create a huge security hole in your software.

I have no idea how to Log Off a user if you are using Basic Authentication.
I would recommend switching to Forms Authentication if you would like to log of your user.

I would also recommend creating another application (a desktop application that will be run on the server) that allows the system administer of your web server to perform maintenance on your application and your server. I strongly recommend against letting a user from the web do this.

-Frinny
May 9 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1702
by: Rajagopal | last post by:
Hi, I have a application which i would require to use for two different set of users. For one set of users i need to set the session timeout as 60 minutes, which i can configure using web.config. But for the other set of users i need to set the session timeout as infinite, which means the session should not get expired. So please some one help me out how to set this property in ASP.NET.
0
1118
by: GP | last post by:
Session time out in IIS is set for 60 min,but why does we get "Object reference not set to an instance of an object. " when the browser is not used for more than 4 to 5 minutes.Please let me know soln if someone know the answer. Thanks GP
0
978
by: Ed Chiu | last post by:
Hi, I have an ASP.Net application, actually it's a modification of ASP.Net Portal starter kit. I am trying to change session timeout to go beyond 20 minutes. I have the following in the web.config file: <sessionState mode="InProc" cookieless="false" timeout="720"/> Does not work at all, session timeout after 20 minutes. I also tried to modified session timeout from IIS manager, does not work either. What can I try next?
2
993
by: thomson | last post by:
Hi all, In the Web.config file , i have specified the Session timeout as 20 minutes. I need a clarification that , when this timeout happens. all the Session variables will be null For eg: once i have logged in i do have a Session=id
1
1471
by: Jeff | last post by:
Question. How would I go about increasing the session time of a user, before they are logged out for inactivity? The reason I want to do this, is because players may have the site open, while actually playing a game. But when they come back to report, they are no longer logged in, but it appears that they are. I assign the cookie when they login using the following code: response.cookies("username") = username
1
5886
by: mansoorsheraz | last post by:
Hi i am, developing a new project for a calling card company. I am, having problems in the session time out. I want to redirect a user to the login page when the session time out expires. All of the pages have session_start() in them to see if the user has actually logged in to the site. I set the session.cookie_lifetime on my login page to 60 seconds and when i click on some url after 60 seconds it takes me to the login page which is very much...
5
1876
by: sam | last post by:
hi all, i continue to footle around on my spanking new ultra 20 (1.8GHz / Opteron Model 144), gradually trying to get to grips with python and unix both. the slow print time in IDLE had already struck me as rather odd. running programs with heavy print requirements from the terminal was a major discovery though, printing being so fast as to make everything appear at once except in the case of literally thousands of items to be
4
2741
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have seen several articles about this subject but I was wondering with ajax is this easer. The articles mentioned client callback and the onbeforeunload event of the browser. Can AJAX be used for this and are there any examples to review. Thank you -- Jerry
1
3098
by: Rogier | last post by:
Hello, I made a simple script with some session variables. When I work in the application, and when I don't use the application for some time, the session vars are erased... even when I set the session time out for 4 hours.... Here is a part of the code: <?PHP
3
1711
by: kolhapur | last post by:
hello, i want to change session time.the session time should differ according to section of my module. i have tried with these function ini_set('session.gc_maxlifetime'), ini_set( 'session.cookie_lifetime', 3600 * 24 );, $currentTimeoutInSecs = ini_get(’session.gc_maxlifetime’) but then also its not happening. please help me.
0
9736
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9226
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7687
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3888
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.