473,549 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get Error info in Custom Error page

I have been struggling with this for days. I feel I must be missing something simple, and I will be eternally grateful for any help. I'm using VS.NET 2003 on XP Pro Sp2.

I searched and found several examples of Custom Error pages for ASP.NET and nothing seemed to work. I zeroed in on "Server.GetLast Error" and found it was always "Nothing".

This is in my web.config:
<customErrors mode="On" defaultRedirect ="error/errors.aspx" />

In errors.aspx, I copied the code below exactly from MSDN "GetLastErr or Method" sample.
When I step through the code from an intentional 404 error, LastError is always "nothing". Any idea why? How do I get some useful error info so I can display a custom message for 404 errors, and something else for other errors.

'--- errors.aspx
Dim LastError As Exception
Dim ErrMessage As String

LastError = Server.GetLastE rror()

If Not LastError Is Nothing Then
ErrMessage = LastError.Messa ge
Else
ErrMessage = "No Errors"
End If

Response.Write( "Last Error = " & ErrMessage)

Nov 19 '05 #1
5 2093
Hi Richard,

Its to late to catch the error at that point.

Instead you should store the Exception inside the Application state bag
from within your global.asax codebehind

Something like...

protected void Application_Err or( object src, EventArgs e ) {
Exception objMyError = Server.GetLastE rror();

HttpContext.Cur rent.Applicatio n.Add("lastErro r",objMyErro r);
Server.ClearErr or();
}

Then in the page_load of errors.aspx you can retrieve the message from
the application object and have ALL the information you need

Inside the page_load you can access the application object you
stored...

HttpContext.Cur rent.Applicatio n.Get("lastErro r")

Then you can access all the properties of GetBaseExceptio n class!!!

Have fun. Let me know how you make out!

Nov 19 '05 #2
Richard,

This article helps to explain a lot as well.

http://msdn.microsoft.com/asp.net/de...stomerrors.asp

Nov 19 '05 #3
Thanks James, that article looks like it has all the answers.

"James Steele" <as***********@ gmail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Richard,

This article helps to explain a lot as well.

http://msdn.microsoft.com/asp.net/de...stomerrors.asp

Nov 19 '05 #4
> Its to late to catch the error at that point.

James has the right idea, but the implementation suggestion is misguided.
protected void Application_Err or( object src, EventArgs e ) {
Exception objMyError = Server.GetLastE rror();
HttpContext.Cur rent.Applicatio n.Add("lastErro r",objMyErro r);
Server.ClearErr or();
}

Then in the page_load of errors.aspx you can retrieve the message from
the application object and have ALL the information you need

This is not safe, since ASP.NET is multi-threaded. You could have two requests
fail at the same time and this code only stores one of those errors. Then
errors.aspx might have someone else's error.

Unrelated to this issue, I'd suggest your error page not use the exception
information at all and instead just show a nice friendly message to the user.
As for the actual error (Exception object) do take James' advice and handle
the Application_Err or in global.asax, get the error via Context.Error and
log the Exception by writing it to a log file, or the system EventLog or
email it to an admin or save it by some other means. You should keep that
information so that an admin can look at it. You specifically don't want
to show any of that information to an end user as they could be malicious
and use it against you and the application.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #5
It amazing what you can learn on forums. Brock is exactly right.

Nov 19 '05 #6

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

Similar topics

9
2983
by: Marina Anufreichik | last post by:
Hi, After deploymnet web application on web server I can access page on local machine and login fine but when I'm trying to access web site from remote machine I can see login page, but when I'm trying to login with correct credentials it give me error: Server Error in '/PDVMgr' Application. ...
1
2045
by: apngss | last post by:
I want to know how to redirect 404 error to custom error page? For example, if test.html doesn't exist and the user type http://www.myserver.com/test.html, it will show my custom error page, instead of the default "The page cannot be found" error page generated by the web browser. Please advise. thanks!!
2
1082
by: George Birbilis | last post by:
Hi all, I'd like to have an error handler proc installed that can grab unhandled errors during a Session before the Session object goes down. I mainly want to log some info kept at the session state upon such an exception, before I propagate it to the system again Now I'm catching the errors at global.asax.vb which is too late, since it's...
9
13888
by: Nick | last post by:
the customError feature is not working. I have it setup as the help says in my web.config file. <customErrors defaultRedirect="DsAppError.aspx" mode="RemoteOnly"/> I tried in a couple different parts of my site to throw a dummy exception and I always get to the page that says change my web.config to the statement above.
7
4985
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying. I created the websetup and built the MSI, have the bundled version. Copied to webserver and ran Websetup.msi. Said I had to remove old version,...
7
2691
by: cpnet | last post by:
I've figured out how to use the <customErrors/> element in my web config file to to redirect 404 errors to a custom error handler. But, it displays an 'ugly' URL in the client's browser. For example, if someone browses to: www.mydomain.com/Users/BobJones/ then my app should display a page with info about Bob Jones....
2
12189
by: Seguros Catatumbo | last post by:
Hello guys, i am trying to port my custom asp 3.0 error page to asp.net. I want to disable debugging in my asp.net projects but i want to show the users a pretty page but that page should send me an email with the details of the error. On classic asp i just went to iis and mapped the 500 error code to error.asp, which does this: set...
1
1764
by: sean_walsh | last post by:
Hi From classic ASP, I had a custom error handling situation that was quite simple. Errors were all redirected to Error.asp. This page would check 2 settings, EmailErrorMessage and DisplayErrorMessage. If EmailErrorMessage was true, it would send an email with the error details. If DisplayErrorMessage was true, it would display the message...
2
6344
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $ ../glibc-2.5/configure --prefix=/mnt/new/Mars/glibc_HQ_test/GLIBC/ install/ --with-__thread --enable-kernel=2.6.11 --enable-shared
0
7541
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...
0
7464
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...
0
7979
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7497
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...
0
7826
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...
1
5385
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...
0
3512
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...
1
1074
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
781
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...

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.