473,747 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to obtain error statusCode form Server.GetLastE rror()?

ad
I use GenericErrorPag e.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.GetLastE rror()?
Nov 17 '05 #1
3 8312
What do you mean by 'statusCode'

Server.GetLastE rror returns a System.Exceptio n object, you will have to cast
to the required exception type (if there is one).

HTH

Ollie Riches
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:e2******** ******@TK2MSFTN GP15.phx.gbl...
I use GenericErrorPag e.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.GetLastE rror()?

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.GetLastE rror() to the required exception type ?
"Ollie Riches" <ol**********@p honeanalyser.ne t> 撰寫於郵件新聞: eD************* @TK2MSFTNGP14.p hx.gbl...
What do you mean by 'statusCode'

Server.GetLastE rror returns a System.Exceptio n object, you will have to
cast to the required exception type (if there is one).

HTH

Ollie Riches
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:e2******** ******@TK2MSFTN GP15.phx.gbl...
I use GenericErrorPag e.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.GetLastE rror()?


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

void Application_Err or(object sender, EventArgs e)
{
//get reference to the source of the exception chain
Exception ex = Server.GetLastE rror().GetBaseE xception();

EventLog.WriteE ntry("MyWeb",
"MESSAGE: " + ex.Message +
"\nSOURCE: " + ex.Source +
"\nFORM: " + Request.Form.To String() +
"\nQUERYSTR ING: " + Request.QuerySt ring.ToString() +
"\nTARGETSI TE: " + ex.TargetSite +
"\nSTACKTRA CE: " + ex.StackTrace,
EventLogEntryTy pe.Error);

//Your other cool code here
}

--Peter

"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:un******** *****@TK2MSFTNG P15.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.GetLastE rror() to the required exception type ?
"Ollie Riches" <ol**********@p honeanalyser.ne t>
撰寫於郵件新聞: eD************* @TK2MSFTNGP14.p hx.gbl...
What do you mean by 'statusCode'

Server.GetLastE rror returns a System.Exceptio n object, you will have to
cast to the required exception type (if there is one).

HTH

Ollie Riches
"ad" <fl****@wfes.tc c.edu.tw> wrote in message
news:e2******** ******@TK2MSFTN GP15.phx.gbl...
I use GenericErrorPag e.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.GetLastE rror()?



Nov 17 '05 #4

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

Similar topics

3
1555
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 statusCode="401" redirect="~/ErrorPages/Error.aspx" /> <error statusCode="403" redirect="~/ErrorPages/Error.aspx" /> <error statusCode="404" redirect="~/ErrorPages/Error.aspx" /> <error statusCode="408" redirect="~/ErrorPages/Error.aspx" />
25
17213
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 being uploaded. I'm also using the HtmlInputFile control to do the uploading. My problem is that when the user's file size exceeds 512k, the page immediately redirects to the "The page cannot be displayed" error page which is very confusing. ...
6
4603
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 form: ========
2
4374
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 the error type in GenericErrorPage.aspx? ---------------------------------------------------------------------------- ----------------------------------------------------
2
1496
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
1058
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 statusCode="404" redirect="~/ErrorPage/NotFound.aspx"/> <error statusCode="500" redirect="~/ErrorPage/InternalError.aspx"/> </customErrors> The error of Code 403 and 404 is clear and it will transfer to a assigned page.
1
1140
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" redirect="~/NoAccess.htm"/> <error statusCode="404" redirect="~/FileNotFound.htm"/> </customErrors> </system.web>
1
1773
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 on screen. Also, if an Administrator was logged in, it would display the message as they could...
5
24520
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, EventArgs e) { Exception exception = Server.GetLastError();
0
8979
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8818
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,...
0
9522
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9354
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9307
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
9223
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...
1
6790
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
4588
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...
0
4860
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.