473,378 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Handling session timeout exception

Hello,

Is there any way I can intercept the session timeout exception, and
1) Run some code routine, ie log the error and it's context
2) Show nicer output to the user

Please do not suggest to increase the session timeout value, or write a code
that doesn't loop. No fools here. There are possible contexts where I want
to keep the session timeout reasonably low, but need to log the occasions,
when it's hit, to rearchitecture those parts of the application.

Thanks for valuable tips,

Pavils Jurjans
Apr 2 '07 #1
5 17410
Not sure why do you want log sessions timeout.
For me the best way scenario is to redirect back to login or to "Your
session has expired" page. I have code like that
If( Session["loggedin"] == null ) Response.Redirect("You login expired");
and of course as soon as user logged in I would put something into
Session["loggedin"] = 1;

You might find this article
http://www.codeproject.com/useritems/SessionForever.asp helpful.
It lets session to stay alive without increasing session's timeout. It's
going to be alive till user has page from your site open in the browser.

George.

"Pavils Jurjans" <pa****@mailbox.riga.lvwrote in message
news:OU**************@TK2MSFTNGP04.phx.gbl...
Hello,

Is there any way I can intercept the session timeout exception, and
1) Run some code routine, ie log the error and it's context
2) Show nicer output to the user

Please do not suggest to increase the session timeout value, or write a
code that doesn't loop. No fools here. There are possible contexts where I
want to keep the session timeout reasonably low, but need to log the
occasions, when it's hit, to rearchitecture those parts of the
application.

Thanks for valuable tips,

Pavils Jurjans

Apr 2 '07 #2
Well, my bad. I wanted to say I want to intercept request timeout exception.
Sorry for the mixup...
Hello,

Is there any way I can intercept the session timeout exception, and
1) Run some code routine, ie log the error and it's context
2) Show nicer output to the user

Please do not suggest to increase the session timeout value, or write a
code that doesn't loop. No fools here. There are possible contexts where I
want to keep the session timeout reasonably low, but need to log the
occasions, when it's hit, to rearchitecture those parts of the
application.

Apr 2 '07 #3
Ok, I've found out that I can insert something like

<customErrors mode="On" defaultRedirect="CustomErrorPage.aspx">
</customErrors>

in the <system.websection of web.config file. But, it's still not clear
how to detect the type of the error (is it request timeout? is it something
else?), when running the code in CustomErrorPage.aspx, and it would also be
valuable to know in which page the timeout happened.

Thanks for any help!

Pavils
Apr 2 '07 #4

<customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
<error statusCode="statuscode" redirect="url"/>
</customErrors>

Put "408" or the relevant error code in the 'statusCode' attribute.

Apr 3 '07 #5
I prefer to use a generic error page, and redirect from there :

<system.web>
<customErrors mode="On" defaultRedirect="Errors.aspx"/>
</system.web>

And, in errors.aspx :

errors.aspx
-----------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException, HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" & appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the inconvenience."
Server.ClearError()
End Sub
</script>
<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true" runat=server/>
<hr>
<p>Return to <a href=http://yourserver.com/>our entry page</a>
</body>
</html>
---------------

Ymmv, of course, and you can add more info to errors.aspx to suit your needs.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Latish Sehgal" <la***********@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
>
<customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
<error statusCode="statuscode" redirect="url"/>
</customErrors>
Put "408" or the relevant error code in the 'statusCode' attribute.

Apr 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pierke | last post by:
Hey guys out there, I really need your help, i am building up a web site, so for security reasons i need to do "some things" before the user log off, and i indeed do it. Now the matter is that...
0
by: TaeHo Yoo | last post by:
Hi all, I am prett new in asp.net. We have a project which has classic asp and asp.net scripts. Obviously this project has a bin directory under the root directory. About 80% of this project...
6
by: Gonenc Ercan | last post by:
Hi, I ve ended up debugging a ASP.NET project (with about 380 files on the project .NET Framework 1.0 on IIS 5.0) which has a memory leak... The memory rises too fast. With about 25-30 active...
7
by: Nikhil Patel | last post by:
Hi all, I am using a Session object in my ASP.Net application to store a value of a Database field. I can access it as ... int iProposalId = Session; The session timeout is set to 20. Now my...
1
by: Oscar Thornell | last post by:
Hi, I have an ASP.NET page that generates an Exception... The Exception is not caught in the executing method...so it propagates to..the Page_Error event handling method.. In that method the...
41
by: Jordan | last post by:
While writing some code, I realized I had never developed a consistent pattern for checking errors from a method. I have two styles I jump back and forth between, but I'm wondering which is...
2
by: tshad | last post by:
This has been driving me crazy. I have been trying to get the error handling working on my system and can get parts of it working and others won't work at all. I found that you can't access...
20
by: Simon Says | last post by:
Hi, I've a login page in which after authenticating it via the Oracle DB, I will stored the user information into the Session. However, when the Session timeout occurs, all of the user...
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.