473,598 Members | 3,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trapping 'compile' errors when aspx page is rendered.

Despite our best efforts occasionally in an aspx file, something like <%=x%>
where x is not defined sqeaks by and I get the ugly asp error message. I want
to be able to identify this particular error and issue a pretty message. I
use the global.asax on application error to handle generalized error
handling. I want to be able to capture and identify the above error.
Nov 19 '05 #1
4 2091
Look into the <customErrors > section in web.config -- it allows you to configure
a nice user friendly page that the user will get redirected to when there
are unhandled exceptions in your application.

http://msdn.microsoft.com/library/de...orssection.asp

-Brock
DevelopMentor
http://staff.develop.com/ballen
Despite our best efforts occasionally in an aspx file, something like
<%=x%> where x is not defined sqeaks by and I get the ugly asp error
message. I want to be able to identify this particular error and issue
a pretty message. I use the global.asax on application error to handle
generalized error handling. I want to be able to capture and identify
the above error.


Nov 19 '05 #2
I beleive when I use when I use the global.asax on application error that it
does get control when this situation occurs. If possible I would like to
identify it there(in the global.asax). All of the error handleing is located
in one program that is server.transfer ed to.

"Brock Allen" wrote:
Look into the <customErrors > section in web.config -- it allows you to configure
a nice user friendly page that the user will get redirected to when there
are unhandled exceptions in your application.

http://msdn.microsoft.com/library/de...orssection.asp

-Brock
DevelopMentor
http://staff.develop.com/ballen
Despite our best efforts occasionally in an aspx file, something like
<%=x%> where x is not defined sqeaks by and I get the ugly asp error
message. I want to be able to identify this particular error and issue
a pretty message. I use the global.asax on application error to handle
generalized error handling. I want to be able to capture and identify
the above error.


Nov 19 '05 #3
I see what you're saying. You use Application_Err or to do all of your error
trapping and then redirect from there. Ok, you can do that, but it's defeating
the purpose of the <customErrors >.

Anyway, to determine if the error comes from your code or elsewhere you should
check to see if the Context.Error is an HttpUnhandledEx ception. If so, then
the unhandled exception is something from your code (like a cast error, DBConnection
error, that sort of thing) that occurs at runtime. The Context.Error.I nnerException
tells the real story as to why the error occured.

If it's a typo in the ASPX page, then the error is a HttpException with an
InnerException of HttpCompileExce ption.

So you might code it like this:

protected void Application_Err or(Object sender, EventArgs e)
{
Exception ex = Context.Error;
if (ex is HttpUnhandledEx ception)
{
// my problem
Server.Transfer ("error.aspx ");
}
else if (ex is HttpException)
{
if (ex.InnerExcept ion is HttpCompileExce ption)
{
// typo in ASPX
Server.Transfer ("SendEmailToDe vTeam.aspx");
}
}

}

Though personally I'd find this very tedious to maintain. We discussed this
a couple fo weeks ago on DevelopMentor's listservs:

http://discuss.develop.com/archives/...B&P=R3885&I=-3

http://discuss.develop.com/archives/...B&P=R3787&I=-3

-Brock
DevelopMentor
http://staff.develop.com/ballen
I beleive when I use when I use the global.asax on application error
that it does get control when this situation occurs. If possible I
would like to identify it there(in the global.asax). All of the error
handleing is located in one program that is server.transfer ed to.

"Brock Allen" wrote:
Look into the <customErrors > section in web.config -- it allows you
to configure a nice user friendly page that the user will get
redirected to when there are unhandled exceptions in your
application.

http://msdn.microsoft.com/library/de...ary/en-us/cpge
nref/html/gngrfcustomerro rssection.asp

-Brock
DevelopMentor
http://staff.develop.com/ballen
Despite our best efforts occasionally in an aspx file, something
like <%=x%> where x is not defined sqeaks by and I get the ugly asp
error message. I want to be able to identify this particular error
and issue a pretty message. I use the global.asax on application
error to handle generalized error handling. I want to be able to
capture and identify the above error.


Nov 19 '05 #4
You are a wonder !!!! Thanks very much for for answering my question exactly
as I was hoping for. Thanks Much !

"Brock Allen" wrote:
I see what you're saying. You use Application_Err or to do all of your error
trapping and then redirect from there. Ok, you can do that, but it's defeating
the purpose of the <customErrors >.

Anyway, to determine if the error comes from your code or elsewhere you should
check to see if the Context.Error is an HttpUnhandledEx ception. If so, then
the unhandled exception is something from your code (like a cast error, DBConnection
error, that sort of thing) that occurs at runtime. The Context.Error.I nnerException
tells the real story as to why the error occured.

If it's a typo in the ASPX page, then the error is a HttpException with an
InnerException of HttpCompileExce ption.

So you might code it like this:

protected void Application_Err or(Object sender, EventArgs e)
{
Exception ex = Context.Error;
if (ex is HttpUnhandledEx ception)
{
// my problem
Server.Transfer ("error.aspx ");
}
else if (ex is HttpException)
{
if (ex.InnerExcept ion is HttpCompileExce ption)
{
// typo in ASPX
Server.Transfer ("SendEmailToDe vTeam.aspx");
}
}

}

Though personally I'd find this very tedious to maintain. We discussed this
a couple fo weeks ago on DevelopMentor's listservs:

http://discuss.develop.com/archives/...B&P=R3885&I=-3

http://discuss.develop.com/archives/...B&P=R3787&I=-3

-Brock
DevelopMentor
http://staff.develop.com/ballen
I beleive when I use when I use the global.asax on application error
that it does get control when this situation occurs. If possible I
would like to identify it there(in the global.asax). All of the error
handleing is located in one program that is server.transfer ed to.

"Brock Allen" wrote:
Look into the <customErrors > section in web.config -- it allows you
to configure a nice user friendly page that the user will get
redirected to when there are unhandled exceptions in your
application.

http://msdn.microsoft.com/library/de...ary/en-us/cpge
nref/html/gngrfcustomerro rssection.asp

-Brock
DevelopMentor
http://staff.develop.com/ballen
Despite our best efforts occasionally in an aspx file, something
like <%=x%> where x is not defined sqeaks by and I get the ugly asp
error message. I want to be able to identify this particular error
and issue a pretty message. I use the global.asax on application
error to handle generalized error handling. I want to be able to
capture and identify the above error.


Nov 19 '05 #5

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

Similar topics

3
661
by: JP | last post by:
I need to be able to trap errors at the application level. I added this code to the Global.asax file. The code I wrote is supposed to get the last error that was generated and write to the event log as well as fire up my email class and generate an email to send me the error. But no matter what I do, I still get the icky looking yellow and white error screens. I’ve turned on customErrors in the web.config but not default URL setting....
13
4461
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently runs into problems on the system where it will actually be used, and since I used so little error-trapping it dies very ungracefully. I will of course try to fix whatever is causing the error and add error-trapping to the functions where the...
4
1540
by: Lowell | last post by:
Any tips for trouble shooting errors when the ASPX page won't even compile? What happens is that VS will "build" the code-behind object and the component that it instantiates, but when I navigate to the ASPX page, I get "An error occurred while try to load the string resources (GetModuleHandle failed with error - 2147023888). Then, I get the message about setting "Debug=true" directives. Those settings are in there. It appears that what is...
3
3819
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a nutshell when testing my ASP.NET (localhost) apps images randomly don't load on the page. Examining the IIS logfile shows the missing images give 401 or 403 errors. Here's an example - 10:15:47 127.0.0.1 GET...
6
1469
by: SMG | last post by:
Hi , Sory for incomplete message in last post here is the actual problem.. I am using following code in web.confiig for trapping all the error through out my site.. <customErrors mode="On" defaultRedirect="WebForm1.aspx"> <error statusCode="404" redirect="ServerError.aspx"></error> <error statusCode="500" redirect="WebForm3.aspx"></error>
2
1563
by: Fred Nelson | last post by:
I'm devloping a VB.NET web application and I'm having a problem with trapping errors and logging the cause of them. When an unexpected error occurs I want to write it to a file - or e-mail it to me. I have set up everything according to the documentation however when I get to my error page "errorpage.aspx" I can't determine why I'm there! In my web.config file I have the line: <customErrors ... defaultredirect="errorpage.aspx"> In...
2
3869
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become visible so the document can be printed and/or modified. This all takes place within one form, in which the Word.Application and Word.Document objects are both private form-level variables. Just to be on the safe side I included this piece of code in...
9
2102
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR | E_PARSE); set_error_handler("SendErrorReport"); function SendErrorReport($errorNumber, $errorMessage, $errorFile, $errorLine, $vars) {
1
2631
by: =?Utf-8?B?SG93YXJkIFBpbnNsZXk=?= | last post by:
I'm trying to convert a Web Site to the Web Application project model and I'm running into compile errors that do not seem to be covered by the guidance I found at "Converting a Web Site Project to a Web Application Project". The issue is that standard ASP.NET controls that are embedded as child controls within the ContentTemplate of the Ajax Control Toolkit's TabContainer/TabPanel are no longer visible to the page (and result in compile...
0
7899
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
8392
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
8397
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...
0
8264
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
5850
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
5438
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
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.