ASP.Net Application life cycle Events in case of Exception RRS feed

  • Question

  • User1048890665 posted


    I get an exception in Authorization module which I am handling in Application_Error handler (also i am calling Server.ClearError()) since i want to sent custom error page with some error info to user.

    I am surprised to see that final response sent to user have error response + response which was actually requested (which means that MVCHandler is processed)

    I am posting below code snippet to simulate similar scenario for quick reference.

    public MvcApplication()
               AuthorizeRequest += (sender, arg) =>
                       throw new Exception("Boooommmm");
               Error += (sender, arg) =>
           private void HandleException()
               var ex = Server.GetLastError();
               Context.Response.Write(String.Format("Some Error Correlation ID to User"));

    And lets say : my HomeController action return simple text like :

    public class HomeController : Controller
            // GET: Home
            public ActionResult Index()
                return Content("Some text from controller");

    If I will run above application and hit /Home/Index, response I will get like :

    "Some Error Correlation ID to User Some text from controller"

    This made me to ask question : Does HttpRuntime continue firing ApplicationEvents in sequence event after exception occurred in one of the event handler ?

    I would like to understand how exception flows in such case (at least glimpse of this would be helpful)

    Note : I already posted this question under ASP.NET MVC forum, but then realized this to be more appropriate forum for this question. There was no way to migrate thread from one forum to another - so I have to duplicate this question (please suggest if some best practices to be obeyed under this situation)

    Thanks in advance!!

    Friday, May 8, 2015 5:27 AM

All replies

  • User1622957740 posted

    After an error the request is ended with HttpApplication.EndRequest() internally. Nothing else in the pipeline fires unless there's some sort of stack cleanup code (try/catch/finally blocks/using statements etc.) that fire. But no events.

    If you want to capture errors in your module/HttpApplication event code and continue on you have to do local error handling with try/catch. Any non-trapped error flow into Application_Error and once it get in there the request is done...

    +++ Rick ---

    Monday, June 29, 2015 2:57 PM
  • User1048890665 posted

    Thanks Rick !!!

    Actually am curious to understand behavior - so as per your response if in Application_Error i call Server.ClearError() then it will clear the stack and subsequent application events in pipeline will fire ? ( In my original question - error in Auth module caught in Application_Error, wherein i called Server.ClearError() and MVC request is processed which indicate maphandler did fired)

    Wednesday, August 26, 2015 8:09 AM
  • User-826859812 posted

    - ASP.NET web application developers sometimes call these the "Blue ... In effect, this gives two separate server pipelines: one for native ... protected void Application_Error(object sender, EventArgs e) { Exception ex = HttpContext. ... ClearError(<g class="gr_ gr_49 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="49" data-gr-id="49">)</g><g class="gr_ gr_49 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style multiReplace" id="49" data-gr-id="49"> ,</g> my custom error message is NOT displayed to the user Lenovo support number if you want to more contact me here

    Thursday, May 31, 2018 5:23 AM
  • User1910655813 posted

     In other words, it creates the application object, request, response and ... So in case there is an issue in one app domain, it does not affect the other app domain <g class="gr_ gr_11 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="11" data-gr-id="11">i</g> m creating a website in QuickBooks support number first <g class="gr_ gr_12 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="12" data-gr-id="12">i</g> create it in word press then after creating in WordPress <g class="gr_ gr_13 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="13" data-gr-id="13">i</g> start doing a coding in my website through .net and <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="5" data-gr-id="5">php</g> check out and see <g class="gr_ gr_4 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="4" data-gr-id="4">is</g> there any fault in my website or not 

    Friday, June 15, 2018 7:24 AM