473,466 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Create 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="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.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.GetLastError();

// 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 1459
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.com> wrote in message
news:eB**************@TK2MSFTNGP10.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="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.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.GetLastError();

// 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.NullReferenceException: Object reference not set to an instance of
an object. "error is at the star(*) "

Exception myError =Server.GetLastError();
*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**************@TK2MSFTNGP15.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.com> wrote in message
news:eB**************@TK2MSFTNGP10.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="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.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.GetLastError();

// 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_Error. This event is raised by ASP.NET
to notify you that there was an unhandled expcetion. In here is where you
can call Server.GetLastError. 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="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.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.GetLastError();
// 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_OnError
method in Global.asax. Handle you excecption here and place whatever you
need in the Session object. Server.ClearError 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.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi MattC,

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

Exception myError =Server.GetLastError();
*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**************@TK2MSFTNGP15.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.com> wrote in message
news:eB**************@TK2MSFTNGP10.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="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.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.GetLastError();

// 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**************@TK2MSFTNGP09.phx.gbl...
What you should do then is capture the error in the Application_OnError
method in Global.asax. Handle you excecption here and place whatever you
need in the Session object. Server.ClearError 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.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi MattC,

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

Exception myError =Server.GetLastError();
*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**************@TK2MSFTNGP15.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.com> wrote in message
news:eB**************@TK2MSFTNGP10.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="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.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.GetLastError();

// 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_Error(Object sender, EventArgs e)
{
//wrtite to event log
Session["LastError"] = SomeMethodToHandleError(Server.GetLastError());
}

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

private void Page_Load(object sender, System.EventArgs e)
{
_myErrorLabel.Text = Session["LastError"].ToString();
}
MattC

"SMG" <SM*@nodmain.com> wrote in message
news:eX**************@TK2MSFTNGP15.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**************@TK2MSFTNGP09.phx.gbl...
What you should do then is capture the error in the Application_OnError
method in Global.asax. Handle you excecption here and place whatever you
need in the Session object. Server.ClearError 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.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi MattC,

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

Exception myError =Server.GetLastError();
*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**************@TK2MSFTNGP15.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.com> wrote in message
news:eB**************@TK2MSFTNGP10.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="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.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.GetLastError();

// 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
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...
2
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...
4
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...
1
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"...
0
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 --> ...
0
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...
2
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...
9
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...
1
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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
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...
1
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...
0
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
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...
0
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...

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.