473,654 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application_Err or, Session, and custom error page

I am trying to write a global custom error page. I thought I would jot down
some of what I've learned so far...

At first I just used the default customErrors section with a defaultRedirect
tag, as such:

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

First thing I found out about this method, is that I didn't have access to
the exception object in my error.aspx page. So this page was going to be
very uninformitive. It appears that the Server.GetLastE rror cannot be
called outside of the Application_Err or event in the global.asax file.

I found this asp.netPRO example that I am now using as a starting point:
http://www.aspnetpro.com/features/20...200305dk_f.asp

In the article the author saves the Exception in a "global" module variable
(how strange) so that he could use it later in his custom error page. This
worked Ok, but this doesn't appear to be thread-safe. So I quickly decided
I should be using a Session variable instead. The author hints that there
are other methods of doing this, but wisely avoids the whole issue. :)

Lots of examples on Google of people trying to stuff their Exception into a
Session("LastEr ror") in the Application_Err or event. Just as many people
wondering why it isn't working. ;(

Turns out you can write to the Session object in the Application_Err or
event, but it won't save it unless you also do a Server.ClearErr or. Ouch!
Take a look http://tinyurl.com/r3xk for a quick explanation.

So now my Application_Err or event is looking like this:

Sub Application_Err or(ByVal sender As Object, ByVal e As EventArgs)

'Grab a reference to the last error. Use InnerException because
'ASP.NET wraps errors here in an HttpUnhandledEx ception.

Session("LastEr ror") = Server.GetLastE rror.InnerExcep tion

Server.ClearErr or() ' must clear error else session state will not
be preserved!!!

' since manually clearing error, must manually redirect...
'Server.Transfe r("~/error.aspx")
Response.Redire ct("~/error.aspx")

End Sub

I have also taken out the defaultRedirect ="error.aspx " tag in the web.config
since this will make it pointless(?)

Notice, I abandoned the server.transfer call in favor on the
response.redire ct. Every single time I try and use server.transfer the page
will ignore my style sheet(!) Anybody?

Since my app is also using forms authentication, I went back an made sure my
error page was accesible whether logged in or not...

<location path="Error.asp x">
<system.web>
<authorizatio n>
<allow users="*" />
</authorization>
</system.web>
</location>

I have seen people using this syntax in their web config: <location
path="~/Error.aspx">, but this doesn't appear to work (or even be
necessary).

Anyways, I hope this helps somebody out there.

Greg


Nov 17 '05 #1
1 5911
Me
Because the error page is in a different directory from
the page where the error occurred. When Server.Transfer
is called, the processing switches to the new page (error
page in this case), but the URL in the browser is still
the initial page where the error occured. So the error
page is effectively being displayed in a different
directory than it's actual location.... causing it not to
be able to find the CSS.

-----Original Message-----

Notice, I abandoned the server.transfer call in favor on
the
response.redire ct. Every single time I try and use
server.transfer the page
will ignore my style sheet(!) Anybody?

Nov 17 '05 #2

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

Similar topics

3
3210
by: Mike Malter | last post by:
I have a general error page that I configured in web.config as <customErrors mode="On" defaultRedirect="CRDefaultError.aspx" /> This error page comes up whenever an error occurs outside of any try/catch blocks. This page has a text box in it that I would like to fill with relevant information about the error. I am trying to put the Server.GetLastError().ToString() in there. It did not work on the page, and I read somewhere that I should...
3
1581
by: MattC | last post by:
When a System.ArgumentOutOfRangeException is throw it gets caught in my Application_Error event. But I want it to be dealt with and then passed to a specific page. I dont want to use redirect becuase i want the Server info that gets picked up by Error.aspx page. Instead of transferring it displays the old yellow and white Server error page. protected void Application_Error(Object sender, EventArgs e) { System.Diagnostics.EventLog myLog...
4
1461
by: Michael | last post by:
Using some example code I've found, I'm trying to do the custom error page thing. I have the following in global.asax.. Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Dim oErr As System.Exception = Server.GetLastError() Session("LastError") = oErr End Sub
6
4555
by: Matt | last post by:
Can anyone give me a good reason to use BOTH application scope Page_Error and the page scope Page_Error when trapping errors in a web application? Is there any real benefit to using the Page_Error if you are already capturing errors in Application_Error? Also, if you have any links to discussions about when to use which function it would be helpful.
1
2425
by: robertlair | last post by:
I am having issues with a production server with the GetLastError() method. Here is what I am doing: Application_Error on Global ASAX: Note: I am doing it this way (with ClearError) because while researching, someone on a post said that Session state would not persist unless I cleared the error... didn't make sense, but it also didn't work before I put this in there too.
8
1991
by: tshad | last post by:
I have an Application_Error function in my Global.asax function that works fine until I try to access my Session variables. I am emailing the results to myself whenever I get an error and would like to get the list of the users Session Variables there were there at the time of the error. But if I add the following line: MyMessage.Body &= "Session Variable" & session("JobTitle") & vbCrLf it goes back to the MS error page instead of...
10
2354
by: Nemisis | last post by:
Hi everyone, I am trying to create a custom error page, that the user gets shown when a error has occurred within my website. The code works perfectly, apart from when an invalid URL is typed in, then i am unable to pass the exception from the global.asax file to the page via the sessionstate. Everytime i try to pass something into the sessionstate i get a error message of 'Object reference not set to an instance of an object.'
8
2566
by: bmukulu | last post by:
Hi, I am trying to add some error handling in a Global.asax file. I am declaring a session variable within the Application_Error procedure. However, everytime i try to pass something into the sessionstate i get a error message of 'Object reference not set to an instance of an object.' Is there any workaround for this? And why am I getting this error? Thanks in advance
1
1887
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
I have a web app that handles errors in the Gloabal.ascx's Application_Error(). It does some logging etc in there and if it throws an error, I want the app to display a static html splash page rather than a yellow screen asp.net error. I have tried setting the custom error page and also a try catch in the application_error with a server.transfer in the catch but it always seems to go to a yellow screen asp.net error page (without any...
0
8294
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,...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
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
7309
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
6162
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
5627
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
4150
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...
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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.