473,511 Members | 14,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to obtain error statusCode form Server.GetLastError()?

ad
I use GenericErrorPage.aspx for the redirect page when some error occur.
I want to show some different according error statusCode .

How can I get error statusCode form Server.GetLastError()?
Nov 17 '05 #1
3 8298
What do you mean by 'statusCode'

Server.GetLastError returns a System.Exception object, you will have to cast
to the required exception type (if there is one).

HTH

Ollie Riches
"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
I use GenericErrorPage.aspx for the redirect page when some error occur.
I want to show some different according error statusCode .

How can I get error statusCode form Server.GetLastError()?

Nov 17 '05 #2
ad
Thanks, When error occur, I redirect usr the a error page.
I want to show custom error message to user.

How can I cast the
Server.GetLastError() to the required exception type ?
"Ollie Riches" <ol**********@phoneanalyser.net> ¼¶¼g©ó¶l¥ó·s»D:eD*************@TK2MSFTNGP14.phx.gb l...
What do you mean by 'statusCode'

Server.GetLastError returns a System.Exception object, you will have to
cast to the required exception type (if there is one).

HTH

Ollie Riches
"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
I use GenericErrorPage.aspx for the redirect page when some error occur.
I want to show some different according error statusCode .

How can I get error statusCode form Server.GetLastError()?


Nov 17 '05 #3
Here's a sample handler (global.asax):

void Application_Error(object sender, EventArgs e)
{
//get reference to the source of the exception chain
Exception ex = Server.GetLastError().GetBaseException();

EventLog.WriteEntry("MyWeb",
"MESSAGE: " + ex.Message +
"\nSOURCE: " + ex.Source +
"\nFORM: " + Request.Form.ToString() +
"\nQUERYSTRING: " + Request.QueryString.ToString() +
"\nTARGETSITE: " + ex.TargetSite +
"\nSTACKTRACE: " + ex.StackTrace,
EventLogEntryType.Error);

//Your other cool code here
}

--Peter

"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:un*************@TK2MSFTNGP15.phx.gbl...
Thanks, When error occur, I redirect usr the a error page.
I want to show custom error message to user.

How can I cast the
Server.GetLastError() to the required exception type ?
"Ollie Riches" <ol**********@phoneanalyser.net>
¼¶¼g©ó¶l¥ó·s»D:eD*************@TK2MSFTNGP14.phx.gb l...
What do you mean by 'statusCode'

Server.GetLastError returns a System.Exception object, you will have to
cast to the required exception type (if there is one).

HTH

Ollie Riches
"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:e2**************@TK2MSFTNGP15.phx.gbl...
I use GenericErrorPage.aspx for the redirect page when some error occur.
I want to show some different according error statusCode .

How can I get error statusCode form Server.GetLastError()?



Nov 17 '05 #4

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

Similar topics

3
1549
by: A.M | last post by:
Hi, I have this code in my web.config: <customErrors mode="On" defaultRedirect="~/ErrorPages/ErrorApp.aspx"> <error statusCode="400" redirect="~/ErrorPages/Error.aspx" /> <error...
25
17144
by: moondaddy | last post by:
I have an application where users need to upload images and in my web.config file I have a setting like this: <httpRuntime maxRequestLength="512" /> Which restricts image larger than 500k from...
6
4585
by: José Joye | last post by:
Hello, I'm currently reading the MS Developing Web applications with c# (and VB.net). In the chapter related to Error management, there is a sample about "Page-Level Error Pages" eg: In my...
2
4359
by: ad | last post by:
I have a customErrors section in Web.config. All error except error 403 and 404, will be redirect to GenericErrorPage.aspx. How can I show the e.Message or some explicit statement according...
2
1485
by: ad | last post by:
Hi, I use the setting below in Web.config <customErrors mode="On" defaultRedirect="~/ErrorPage/GenericErrorPage.aspx" /> How could we get error statusCode when GenericErrorPage is load?
0
1046
by: ad | last post by:
I use these setting in Web.Config <customErrors mode="On" defaultRedirect="~/ErrorPage/GenericErrorPage.aspx"> <error statusCode="403" redirect="~/ErrorPage/NoAccess.aspx"/> <error...
1
1128
by: jobs | last post by:
Hello. I've got a customerrors section in my web.config that redirects all errors to an ErrorPage.aspx <customErrors defaultRedirect="~/ErrorPage.aspx"> <error statusCode="403"...
1
1762
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...
5
24491
by: rote | last post by:
I'm using ASP.NET 2.0 and i have copied and pasted the code below to my Global.asax file but it desn't trap the error I want to trap the 401 access denied void Application_Error(object sender,...
0
7252
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,...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
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...
0
7517
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...
0
5676
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,...
0
4743
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
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...

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.