Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
Hi,

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.

C#
public MvcApplication()
       {
           AuthorizeRequest += (sender, arg) =>
               {
                   throw new Exception("Boooommmm");
               };


           Error += (sender, arg) =>
               {
                   HandleException();
               };

       }

       private void HandleException()
       {
           var ex = Server.GetLastError();
           Context.Response.Write(String.Format("Some Error Correlation ID to User"));
           Server.ClearError();
       }


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

SQL
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)

Thanks in advance!!
Rahul
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900