Get error page name

D

David C

I have a Global.asax file that has an Application_Error subroutine that
emails me when an error occurs using the code below and some smtp stuff.

Dim ex As Exception = HttpContext.Current.Server.GetLastError()

I would like to be able to also get the name of the page that generated the
error. I found the item below but I am not sure if this will work. Can
anyone help? Thanks.

David

Dim strPageFrom As String =
HttpContext.Current.Server.GetLastError.Source
 
G

Gregory A. Beamer

I have a Global.asax file that has an Application_Error subroutine
that emails me when an error occurs using the code below and some smtp
stuff.

Dim ex As Exception = HttpContext.Current.Server.GetLastError()

I would like to be able to also get the name of the page that
generated the error. I found the item below but I am not sure if this
will work. Can anyone help? Thanks.

David

Dim strPageFrom As String =
HttpContext.Current.Server.GetLastError.Source

Since you are already pulling the Exception object, you have some
choices here.

For example:

ex.Source - Application that threw the exception

ex.Target - Method that threw the exception

ex.StackTrace - information about how you got to this point in code.
Very useful information

ex.Message - the exception that was thrown

ex.GetType() - specific type of exception thrown

ex.InnerException - This will generally only be useful if you are using
third party libs that throw custom exceptions or you have coded your own
exception, but it is useful to check this if you want full details. If
null, you can ignore reporting it.

You can also look at ex.HResult, but based on your post, the info you
get from this will probably be like a foreign language.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
P

Patrice

David C said:
I would like to be able to also get the name of the page that generated
the error. I found the item below but I am not sure if this will work.
Can anyone help? Thanks.

This is not because GetLastError returns information about the error that
you have to get all through this. In particular you can still have access to
the current request. From global asax you have Request.AbsolutePath (or you
could use System.Web.HttpContext.Current as usual if from you want this from
a standalone error handling routine)
 
D

David C

Patrice said:
This is not because GetLastError returns information about the error that
you have to get all through this. In particular you can still have access
to the current request. From global asax you have Request.AbsolutePath (or
you could use System.Web.HttpContext.Current as usual if from you want
this from a standalone error handling routine)
I could not use Request.AbsolutePath in my Global.asax
Do I need to add a Namespace to get it?

David
 
P

Patrice

In which method, your own or a standard one ? If this method belongs to the
Application object, the Request member should be provided by this object.

As mentioned in my previous post if this is in another method you can also
use System.Web.HttpContext.Current to get the current http context (which
exposes the Request).
 
D

David C

Patrice said:
In which method, your own or a standard one ? If this method belongs to
the Application object, the Request member should be provided by this
object.

As mentioned in my previous post if this is in another method you can also
use System.Web.HttpContext.Current to get the current http context (which
exposes the Request).
When I go into the Global.asax and type Request and then a period, the
intellisense does not bring up AbsolutePath as a selection. I looked up
AbsolutePath and it is a member of Uri. Is that what I need to use to get
the page name that caused the error? I know that it is in some of the Stack
Trace results that show the page name and line number. Thanks.

David
 
P

Patrice

When I go into the Global.asax and type Request and then a period, the
intellisense does not bring up AbsolutePath as a selection. I looked up
AbsolutePath and it is a member of Uri. Is that what I need to use to get
the page name that caused the error? I know that it is in some of the
Stack Trace results that show the page name and line number. Thanks.

Sorry, this is actually Request.Url.AbsolutePath (or whatever part you would
want)...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top