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:
========
<%@ Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
errorPage="ErrDefault1.aspx"%>
I have placed a button on the form and in the code behind just thrown an
Exception.
in ErrDefaulst1.aspx:
==============
private void Page_Load(object sender, System.EventArgs e)
{
if (Server.GetLastError() != null)
litError.Text="<h3>" + Server.GetLastError().Message + "</h3>";
else
litError.Text= "<h3>Unkown Error occured...</h3>";
Server.ClearError();
}
It is said, that is is possible to use the Server.GetLastError() in the
error page. However, it is always null.
Did I miss something?
Thanks,
José 6 4578
I asked this.. and got answered by myself:) a few days ago..
My answer:
"Since you are redirected to another errorpage you loose the GetLatsetError
information, cause you are not on that page anymore.. BUT.. if you in
Global.aspx in Page_Eerror event (where it's still accessible) put
Server.GetLastError in a SESSION variable.. you can get it thru that on the
Errorpage .."
/Lars
"José Joye" <jo*******@KILLTHESPAMSbluewin.ch> skrev i meddelandet
news:us**************@TK2MSFTNGP11.phx.gbl... 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: ======== <%@ Page language="c#" Codebehind="TestErrOnPage.aspx.cs" AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage" errorPage="ErrDefault1.aspx"%>
I have placed a button on the form and in the code behind just thrown an Exception.
in ErrDefaulst1.aspx: ==============
private void Page_Load(object sender, System.EventArgs e) { if (Server.GetLastError() != null) litError.Text="<h3>" + Server.GetLastError().Message + "</h3>"; else litError.Text= "<h3>Unkown Error occured...</h3>"; Server.ClearError(); }
It is said, that is is possible to use the Server.GetLastError() in the error page. However, it is always null. Did I miss something?
Thanks, José
Thanks for the answer. However, I'm not too clear about it.
1) I thaught that the Page_Error() method has to be located in the Web class
and not in the Global.aspx. Did I misundertood what you explained me.
2) With the following:
<%@ Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
errorPage="ErrDefault1.aspx"%>
I was trying to get rid of the Page_Error() method and have a "kind of
automatic" redirection to the ErrDefault1.aspx page in case of error.
If I make usage of the Page_Error() method, I do not see the reason of
having the "errorPage="ErrDefault1.aspx"%>" statement in my aspx file.
Thanks,
José
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... I asked this.. and got answered by myself:) a few days ago..
My answer:
"Since you are redirected to another errorpage you loose the
GetLatsetError information, cause you are not on that page anymore.. BUT.. if you in Global.aspx in Page_Eerror event (where it's still accessible) put Server.GetLastError in a SESSION variable.. you can get it thru that on
the Errorpage .."
/Lars
"José Joye" <jo*******@KILLTHESPAMSbluewin.ch> skrev i meddelandet news:us**************@TK2MSFTNGP11.phx.gbl... 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: ======== <%@ Page language="c#" Codebehind="TestErrOnPage.aspx.cs" AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage" errorPage="ErrDefault1.aspx"%>
I have placed a button on the form and in the code behind just thrown an Exception.
in ErrDefaulst1.aspx: ==============
private void Page_Load(object sender, System.EventArgs e) { if (Server.GetLastError() != null) litError.Text="<h3>" + Server.GetLastError().Message + "</h3>"; else litError.Text= "<h3>Unkown Error occured...</h3>"; Server.ClearError(); }
It is said, that is is possible to use the Server.GetLastError() in the error page. However, it is always null. Did I miss something?
Thanks, José
Hi José,
I think Lars is suggesting having the exception handled, or at least its
details stored somewhere, in the Application_Error method in "Global.asax".
It may be that perhaps your exception page doesn't need to show the
details of the exception to the end user, although I, of course, don't
know the details of your scenario. If you're principally interested in
apologizing to the user and publishing the details of the exception
somewhere developers can get hold of it (event log, email, file etc) you
could use Microsoft Exception Management Application block from: http://msdn.microsoft.com/library/de...ml/emab-rm.asp
You could get around adding errorPage and Page_Error() code your
individual aspx pages by also setting the default error redirect in your
webconfig <customErrors> section:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
</customErrors>
(mode attribute is explained in the comments preceding the section in
web.config, "On" is likely to be necessary for testing and debugging if
you're serving the pages from your own machine)
In this way your page exception would not get handled on the page, would
propogate to the Global.asax handler, which would publish the exception
to whatever log your wanted, or perhaps store it in some accessible
storage, and *not* clear the error. Then the exception would propogate
to the defaultRedirect page in the web.config file, which could
apologize to the user and possibly use any persisted exception details.
This works quite neatly, although it is worth noting that any resources
not handled by the ASP.NET isapi filter (for instance any legacy asp
pages you may be obliged to include) will require additional handling.
There may well be faults with this method of handling things, and to be
honest it feels a little cumbersome defaulting to allowing the exception
to escalate to the application level, but I've certainly been obliged to
do it, and application level handling definitely should exist.
Hope I didn't deviate to far from your question!
Regards,
Duncan Kennedy.
Hi Duncan,
Thanks a lot for your really interesting reply.
I'm actually in the process of getting up to speed with ASP.NET (sorry for
the stupid questions ;-) )
I still have an open question related to this topic.
Say an exception is thrown in the Rendering part (preRendering/Rendering) of
the form.
This is actually out my scope. In that situation, if I do not have a
Page_Error() defined, how could I record the kind of error that occured.
If I understand it correctly, as soon as I get out of the Page scope, I will
not have the exception available anymore if I did not save it manually
somewhere (eg. : Session bag).
If I defined an Application_Error handler (in Global.asax) will I have this
information available?
Thanks,
José
"Duncan Kennedy" <yo*****************************@achilles.com> wrote in
message news:uc**************@tk2msftngp13.phx.gbl... Hi José,
I think Lars is suggesting having the exception handled, or at least its details stored somewhere, in the Application_Error method in
"Global.asax". It may be that perhaps your exception page doesn't need to show the details of the exception to the end user, although I, of course, don't know the details of your scenario. If you're principally interested in apologizing to the user and publishing the details of the exception somewhere developers can get hold of it (event log, email, file etc) you could use Microsoft Exception Management Application block from:
http://msdn.microsoft.com/library/de...ml/emab-rm.asp
You could get around adding errorPage and Page_Error() code your individual aspx pages by also setting the default error redirect in your webconfig <customErrors> section:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx"> </customErrors>
(mode attribute is explained in the comments preceding the section in web.config, "On" is likely to be necessary for testing and debugging if you're serving the pages from your own machine)
In this way your page exception would not get handled on the page, would propogate to the Global.asax handler, which would publish the exception to whatever log your wanted, or perhaps store it in some accessible storage, and *not* clear the error. Then the exception would propogate to the defaultRedirect page in the web.config file, which could apologize to the user and possibly use any persisted exception details.
This works quite neatly, although it is worth noting that any resources not handled by the ASP.NET isapi filter (for instance any legacy asp pages you may be obliged to include) will require additional handling.
There may well be faults with this method of handling things, and to be honest it feels a little cumbersome defaulting to allowing the exception to escalate to the application level, but I've certainly been obliged to do it, and application level handling definitely should exist.
Hope I didn't deviate to far from your question!
Regards,
Duncan Kennedy.
Hi José,
I'm sorrier for the stupid answers...
If an exception either occurs on a page before a Page_Error() handler
has been assigned or is not cleared by by a Page_Error() method then the
application will throw a HttpUnhandledException exception, which will
contain in its "innerException" property the exception that was
unhandled on the page.
As such you should still have your page exception when you're coding at
the Application_Error level, it will just be wrapped in another
exception. You could persist this somewhere appropriate if you wanted
to keep it to give a verbose report to the user when you finally
transferred the scope to an error page (Server.Redirect, defaultError in
web.config etc).
I hope this helps, Michael O'Donovan pointed out the following url on
error handling in another thread which might be useful: http://msdn.microsoft.com/asp.net/us...stomErrors.asp
Best of luck,
Duncan.
José Joye wrote: Hi Duncan,
Thanks a lot for your really interesting reply. I'm actually in the process of getting up to speed with ASP.NET (sorry for the stupid questions ;-) )
I still have an open question related to this topic. Say an exception is thrown in the Rendering part (preRendering/Rendering) of the form. This is actually out my scope. In that situation, if I do not have a Page_Error() defined, how could I record the kind of error that occured. If I understand it correctly, as soon as I get out of the Page scope, I will not have the exception available anymore if I did not save it manually somewhere (eg. : Session bag).
If I defined an Application_Error handler (in Global.asax) will I have this information available?
Thanks, José
"Duncan Kennedy" <yo*****************************@achilles.com> wrote in message news:uc**************@tk2msftngp13.phx.gbl...
Hi José,
I think Lars is suggesting having the exception handled, or at least its details stored somewhere, in the Application_Error method in
"Global.asax".
It may be that perhaps your exception page doesn't need to show the details of the exception to the end user, although I, of course, don't know the details of your scenario. If you're principally interested in apologizing to the user and publishing the details of the exception somewhere developers can get hold of it (event log, email, file etc) you could use Microsoft Exception Management Application block from:
http://msdn.microsoft.com/library/de...ml/emab-rm.asp
You could get around adding errorPage and Page_Error() code your individual aspx pages by also setting the default error redirect in your webconfig <customErrors> section:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx"> </customErrors>
(mode attribute is explained in the comments preceding the section in web.config, "On" is likely to be necessary for testing and debugging if you're serving the pages from your own machine)
In this way your page exception would not get handled on the page, would propogate to the Global.asax handler, which would publish the exception to whatever log your wanted, or perhaps store it in some accessible storage, and *not* clear the error. Then the exception would propogate to the defaultRedirect page in the web.config file, which could apologize to the user and possibly use any persisted exception details.
This works quite neatly, although it is worth noting that any resources not handled by the ASP.NET isapi filter (for instance any legacy asp pages you may be obliged to include) will require additional handling.
There may well be faults with this method of handling things, and to be honest it feels a little cumbersome defaulting to allowing the exception to escalate to the application level, but I've certainly been obliged to do it, and application level handling definitely should exist.
Hope I didn't deviate to far from your question!
Regards,
Duncan Kennedy.
Thanks a lot for the explanation and for the great reference. I think that
I'm pretty clear on this topic now :-))
José
"Duncan Kennedy" <yo*****************************@achilles.com> a écrit dans
le message de news:eu**************@tk2msftngp13.phx.gbl... Hi José,
I'm sorrier for the stupid answers...
If an exception either occurs on a page before a Page_Error() handler has been assigned or is not cleared by by a Page_Error() method then the application will throw a HttpUnhandledException exception, which will contain in its "innerException" property the exception that was unhandled on the page.
As such you should still have your page exception when you're coding at the Application_Error level, it will just be wrapped in another exception. You could persist this somewhere appropriate if you wanted to keep it to give a verbose report to the user when you finally transferred the scope to an error page (Server.Redirect, defaultError in web.config etc).
I hope this helps, Michael O'Donovan pointed out the following url on error handling in another thread which might be useful:
http://msdn.microsoft.com/asp.net/us...stomErrors.asp Best of luck,
Duncan.
José Joye wrote: Hi Duncan,
Thanks a lot for your really interesting reply. I'm actually in the process of getting up to speed with ASP.NET (sorry
for the stupid questions ;-) )
I still have an open question related to this topic. Say an exception is thrown in the Rendering part
(preRendering/Rendering) of the form. This is actually out my scope. In that situation, if I do not have a Page_Error() defined, how could I record the kind of error that occured. If I understand it correctly, as soon as I get out of the Page scope, I
will not have the exception available anymore if I did not save it manually somewhere (eg. : Session bag).
If I defined an Application_Error handler (in Global.asax) will I have
this information available?
Thanks, José
"Duncan Kennedy" <yo*****************************@achilles.com> wrote in message news:uc**************@tk2msftngp13.phx.gbl...
Hi José,
I think Lars is suggesting having the exception handled, or at least its details stored somewhere, in the Application_Error method in
"Global.asax".
It may be that perhaps your exception page doesn't need to show the details of the exception to the end user, although I, of course, don't know the details of your scenario. If you're principally interested in apologizing to the user and publishing the details of the exception somewhere developers can get hold of it (event log, email, file etc) you could use Microsoft Exception Management Application block from:
http://msdn.microsoft.com/library/de...ml/emab-rm.asp You could get around adding errorPage and Page_Error() code your individual aspx pages by also setting the default error redirect in your webconfig <customErrors> section:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx"> </customErrors>
(mode attribute is explained in the comments preceding the section in web.config, "On" is likely to be necessary for testing and debugging if you're serving the pages from your own machine)
In this way your page exception would not get handled on the page, would propogate to the Global.asax handler, which would publish the exception to whatever log your wanted, or perhaps store it in some accessible storage, and *not* clear the error. Then the exception would propogate to the defaultRedirect page in the web.config file, which could apologize to the user and possibly use any persisted exception details.
This works quite neatly, although it is worth noting that any resources not handled by the ASP.NET isapi filter (for instance any legacy asp pages you may be obliged to include) will require additional handling.
There may well be faults with this method of handling things, and to be honest it feels a little cumbersome defaulting to allowing the exception to escalate to the application level, but I've certainly been obliged to do it, and application level handling definitely should exist.
Hope I didn't deviate to far from your question!
Regards,
Duncan Kennedy.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Goethals Frederik |
last post by:
hi,
I have a little problem with the function "Page.GetPostBackClientHyperlink".
First some description of my page:
It is a simple testpage for testing "selecting a row af the datagrid by...
|
by: BELIUS |
last post by:
Hi all,
I am implementing a "Print this Page" function in my ASP.NET application.
This function should print a part of the page and I would like to use an
MSDN Style "Print this Page".
I'm...
|
by: dhnriverside |
last post by:
Hi
I've got the following in my aspx
<asp:textbox id="findwhat" OnKeyPress="javascript:suggest()"></asp:textbox>
and the suggest function
function suggest()
{
|
by: soren625 |
last post by:
What I am trying to do is grab a little snippet of data from a remote
page based on user input in a form. Take a look at this page:
http://www.qrz.com/kb2gsd
What I want to do is: when a user...
|
by: Unnikrishnan |
last post by:
Hi Pals,
I want to know about that how IIS Server comes to know about
the starting page of any application built in C# or Vb.NET.
...
|
by: STILL LEARNING |
last post by:
I'm not sure if this can even be done, but what prompts the question
is my desire to be able to create an "Uber Link" script/code of some
sort, such that even if the html page contains nothing but...
|
by: Morgan Cheng |
last post by:
Without IIS configuration, is it possible to set "default page" in
web.config?
I am curious about that because I am developing in VS2005 with ASP.NET
Development Server. I want to config it with...
|
by: sid |
last post by:
Can someone tell me how to detect "Action Cancelled" page with out
polling.
I have a frame set and I want to make sure the other frame is
displaying what it is supposed to without polling. For...
|
by: lander |
last post by:
I've read the page life cycle thing in msdn, still, i'm getting a bit
confused of thinking how all the things are going under the hood...
I know that when page loading, that the controls'...
|
by: MrCorbeaux |
last post by:
My "Email a Webpage" form works find except when the end user receives the email, the URL is text only and not a hyperlink.
The "Email a Page" form calls the URL from the previous page using:
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
| |