473,785 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CustomErrors Trapping in a Page -

SMG
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="Serve rError.aspx"></error>
<error statusCode="500 " redirect="WebFo rm3.aspx"></error>
</customErrors>

It works very fine... but On the final page e.g WebForm3.aspx I want catch
the error and want to show it on the screen.
so i wrote following code in webform3.aspx but it throws an error

// Create an Exception object from the Last error
//that occurred on the server
Exception myError =Server.GetLast Error();

// Get the error message
string str = "Error Message :" + myError.Message ;

It doesn't work it gives an error at following line
strErrorMsg += "\n\nError Message :" + myError.Message ;

Regards,
Shailesh Gajare
Nov 19 '05 #1
6 1482
What error is it giving? Do you have any error handling in your
global.asax.(vb/cs).

Place try..catch block around GetLasterError to see what exception is being
thrown.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:eB******** ******@TK2MSFTN GP10.phx.gbl...
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="Serve rError.aspx"></error>
<error statusCode="500 " redirect="WebFo rm3.aspx"></error>
</customErrors>

It works very fine... but On the final page e.g WebForm3.aspx I want catch
the error and want to show it on the screen.
so i wrote following code in webform3.aspx but it throws an error

// Create an Exception object from the Last error
//that occurred on the server
Exception myError =Server.GetLast Error();

// Get the error message
string str = "Error Message :" + myError.Message ;

It doesn't work it gives an error at following line
strErrorMsg += "\n\nError Message :" + myError.Message ;

Regards,
Shailesh Gajare

Nov 19 '05 #2
SMG
Hi MattC,

It says:::
System.NullRefe renceException: Object reference not set to an instance of
an object. "error is at the star(*) "

Exception myError =Server.GetLast Error();
*string str = "Error Message :" + myError.Message ;
My mode of customErrors is Off so that it shows the error on the screen

Objective : If we get any error on any of the pages through out the site,
then it should show a single customize page where
the error is explained and a email is shooted at one id.
Regards,
Shailesh Gajare
"MattC" <m@m.com> wrote in message
news:eI******** ******@TK2MSFTN GP15.phx.gbl...
What error is it giving? Do you have any error handling in your
global.asax.(vb/cs).

Place try..catch block around GetLasterError to see what exception is being
thrown.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:eB******** ******@TK2MSFTN GP10.phx.gbl...
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="Serve rError.aspx"></error>
<error statusCode="500 " redirect="WebFo rm3.aspx"></error>
</customErrors>

It works very fine... but On the final page e.g WebForm3.aspx I want catch
the error and want to show it on the screen.
so i wrote following code in webform3.aspx but it throws an error

// Create an Exception object from the Last error
//that occurred on the server
Exception myError =Server.GetLast Error();

// Get the error message
string str = "Error Message :" + myError.Message ;

It doesn't work it gives an error at following line
strErrorMsg += "\n\nError Message :" + myError.Message ;

Regards,
Shailesh Gajare

Nov 19 '05 #3
The problem is that using the customErrors causes a redirect to the server.
The redirect is a completely ew request into the server and thus the prior
error information is gone. The customErrors is a great way to automatically
redirect the client to a user-friendly error page.

Now, I suspect you want to capture the error information. This should be
done in global.asax in Application_Err or. This event is raised by ASP.NET
to notify you that there was an unhandled expcetion. In here is where you
can call Server.GetLastE rror. Once you have the error, do whatever you need
to with it like log it to the EventLog a log file, email it to an admin,
whatever.

Now just in case you reply asking how you can show the error on the error
page, I'd say you shouldn't. Never show error information to clients 1) for
user friendliness reasons and 2) security reasons.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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="Serve rError.aspx"></error>
<error statusCode="500 " redirect="WebFo rm3.aspx"></error>
</customErrors>
It works very fine... but On the final page e.g WebForm3.aspx I want
catch
the error and want to show it on the screen.
so i wrote following code in webform3.aspx but it throws an error
// Create an Exception object from the Last error
//that occurred on the server
Exception myError =Server.GetLast Error();
// Get the error message
string str = "Error Message :" + myError.Message ;
It doesn't work it gives an error at following line
strErrorMsg += "\n\nError Message :" + myError.Message ;
Regards,
Shailesh Gajare


Nov 19 '05 #4
What you should do then is capture the error in the Application_OnE rror
method in Global.asax. Handle you excecption here and place whatever you
need in the Session object. Server.ClearErr or then transfer the user to your
custom page. Here you can pull out you details from the Session/send emails
etc.

Alternatively just log the error in the event log. Then set customErrors
mode to RemotrOnly and redirect to your nice friendly page.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi MattC,

It says:::
System.NullRefe renceException: Object reference not set to an instance of
an object. "error is at the star(*) "

Exception myError =Server.GetLast Error();
*string str = "Error Message :" + myError.Message ;
My mode of customErrors is Off so that it shows the error on the screen

Objective : If we get any error on any of the pages through out the site,
then it should show a single customize page where
the error is explained and a email is shooted at one id.
Regards,
Shailesh Gajare
"MattC" <m@m.com> wrote in message
news:eI******** ******@TK2MSFTN GP15.phx.gbl...
What error is it giving? Do you have any error handling in your
global.asax.(vb/cs).

Place try..catch block around GetLasterError to see what exception is
being
thrown.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:eB******** ******@TK2MSFTN GP10.phx.gbl...
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="Serve rError.aspx"></error>
<error statusCode="500 " redirect="WebFo rm3.aspx"></error>
</customErrors>

It works very fine... but On the final page e.g WebForm3.aspx I want
catch
the error and want to show it on the screen.
so i wrote following code in webform3.aspx but it throws an error

// Create an Exception object from the Last error
//that occurred on the server
Exception myError =Server.GetLast Error();

// Get the error message
string str = "Error Message :" + myError.Message ;

It doesn't work it gives an error at following line
strErrorMsg += "\n\nError Message :" + myError.Message ;

Regards,
Shailesh Gajare


Nov 19 '05 #5
SMG
Thanks Mattc,
That's a good idea. But this the way we used to do in ASP what is the best
way we can do it in ASP.Net
One more I am allowed to use session then how do I show the error on the
next page, If I pass it through a querystring that is not a good way...
then what are other options I have.

Can I use Context.Handler or something like this...

One more I am trying to avoid writing the even log entry or writing in a log
file as if there is any problem in the global.asax this will halt my entire
application

What is Industry standard/ best practices for this?

Thanks once again
Shailesh G

"MattC" <m@m.com> wrote in message
news:ub******** ******@TK2MSFTN GP09.phx.gbl...
What you should do then is capture the error in the Application_OnE rror
method in Global.asax. Handle you excecption here and place whatever you
need in the Session object. Server.ClearErr or then transfer the user to your
custom page. Here you can pull out you details from the Session/send emails
etc.

Alternatively just log the error in the event log. Then set customErrors
mode to RemotrOnly and redirect to your nice friendly page.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi MattC,

It says:::
System.NullRefe renceException: Object reference not set to an instance of
an object. "error is at the star(*) "

Exception myError =Server.GetLast Error();
*string str = "Error Message :" + myError.Message ;
My mode of customErrors is Off so that it shows the error on the screen

Objective : If we get any error on any of the pages through out the site,
then it should show a single customize page where
the error is explained and a email is shooted at one id.
Regards,
Shailesh Gajare
"MattC" <m@m.com> wrote in message
news:eI******** ******@TK2MSFTN GP15.phx.gbl...
What error is it giving? Do you have any error handling in your
global.asax.(vb/cs).

Place try..catch block around GetLasterError to see what exception is
being
thrown.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:eB******** ******@TK2MSFTN GP10.phx.gbl...
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="Serve rError.aspx"></error>
<error statusCode="500 " redirect="WebFo rm3.aspx"></error>
</customErrors>

It works very fine... but On the final page e.g WebForm3.aspx I want
catch
the error and want to show it on the screen.
so i wrote following code in webform3.aspx but it throws an error

// Create an Exception object from the Last error
//that occurred on the server
Exception myError =Server.GetLast Error();

// Get the error message
string str = "Error Message :" + myError.Message ;

It doesn't work it gives an error at following line
strErrorMsg += "\n\nError Message :" + myError.Message ;

Regards,
Shailesh Gajare


Nov 19 '05 #6
You'll find that writing to the event log in the global.asax is one of most
common ways to document errors in an app.

try something along the lines of:

Global.asax.cs
protected void Application_Err or(Object sender, EventArgs e)
{
//wrtite to event log
Session["LastError"] = SomeMethodToHan dleError(Server .GetLastError() );
}

web.config
<customErrors defaultRedirect ="Error.aspx " mode="RemoteOnl y" />
Error.aspx.cs

private void Page_Load(objec t sender, System.EventArg s e)
{
_myErrorLabel.T ext = Session["LastError"].ToString();
}
MattC

"SMG" <SM*@nodmain.co m> wrote in message
news:eX******** ******@TK2MSFTN GP15.phx.gbl...
Thanks Mattc,
That's a good idea. But this the way we used to do in ASP what is the best
way we can do it in ASP.Net
One more I am allowed to use session then how do I show the error on the
next page, If I pass it through a querystring that is not a good way...
then what are other options I have.

Can I use Context.Handler or something like this...

One more I am trying to avoid writing the even log entry or writing in a
log
file as if there is any problem in the global.asax this will halt my
entire
application

What is Industry standard/ best practices for this?

Thanks once again
Shailesh G

"MattC" <m@m.com> wrote in message
news:ub******** ******@TK2MSFTN GP09.phx.gbl...
What you should do then is capture the error in the Application_OnE rror
method in Global.asax. Handle you excecption here and place whatever you
need in the Session object. Server.ClearErr or then transfer the user to
your
custom page. Here you can pull out you details from the Session/send
emails
etc.

Alternatively just log the error in the event log. Then set customErrors
mode to RemotrOnly and redirect to your nice friendly page.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi MattC,

It says:::
System.NullRefe renceException: Object reference not set to an instance of
an object. "error is at the star(*) "

Exception myError =Server.GetLast Error();
*string str = "Error Message :" + myError.Message ;
My mode of customErrors is Off so that it shows the error on the screen

Objective : If we get any error on any of the pages through out the site,
then it should show a single customize page where
the error is explained and a email is shooted at one id.
Regards,
Shailesh Gajare
"MattC" <m@m.com> wrote in message
news:eI******** ******@TK2MSFTN GP15.phx.gbl...
What error is it giving? Do you have any error handling in your
global.asax.(vb/cs).

Place try..catch block around GetLasterError to see what exception is
being
thrown.

MattC
"SMG" <SM*@nodmain.co m> wrote in message
news:eB******** ******@TK2MSFTN GP10.phx.gbl...
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="Serve rError.aspx"></error>
<error statusCode="500 " redirect="WebFo rm3.aspx"></error>
</customErrors>

It works very fine... but On the final page e.g WebForm3.aspx I want
catch
the error and want to show it on the screen.
so i wrote following code in webform3.aspx but it throws an error

// Create an Exception object from the Last error
//that occurred on the server
Exception myError =Server.GetLast Error();

// Get the error message
string str = "Error Message :" + myError.Message ;

It doesn't work it gives an error at following line
strErrorMsg += "\n\nError Message :" + myError.Message ;

Regards,
Shailesh Gajare



Nov 19 '05 #7

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....
2
2009
by: Matthias S. | last post by:
Hi there, in my customErrors defaultRedirect-Page I'd like to know what the failing status-code actually was, eg. 404 (file not found), so that I can display a message accordingly. any ideas how to get hold of it? Any help is greatly appreceated. -- /Matthias
4
2101
by: Bill | last post by:
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.
1
1078
by: SMG | last post by:
Hi All, 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> </customErrors>
0
1124
by: Michel Lapointe | last post by:
Hello, I have a small problem enabling customererrors when combine with <location> tag A cut version of my web.config (which show the problem) is <!-- Web.Config Configuration File --> <configuration>
0
871
by: John Clark | last post by:
I want to analyze HTTP errors, i.e. 404, 403, etc. using a customErrors redirect page. When the page is called I am using aspxerrorpath to record the error page path. However, I would like to report the actual error code. Is the error code, i.e. 404, 403 available in any of the Page objects available to the redirect page? Thanks for your help.
2
1568
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...
9
4273
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. Is it programatically possible in VB.NET to read the contents of web.config's <customErrorselement? I looked at using ConfigurationSettings.AppSettings, but that doesn't work. I need to read the value of redirect from the error statusCode 404. My web.config looks like this: <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx"> <error statusCode="404" redirect="Error404.aspx" /> </customErrors>
1
1767
by: JJ | last post by:
I've a strange problem: My customErrors section in my web.config doesn't seem to be working on the live host. By that, I mean that when I type in an address of a page that doesn't exist, I get the standard 404 error page and not my custom one. It works fine on both my visual studio web server and my local IIS, with exaclty the same web.config. The custom error section reads:
0
9646
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
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
10350
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
10157
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
7505
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
6742
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
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.