title: How do i use Application_Error in ASP.NET MVC?
body: <p>I want to use Application_Error with my MVC project, but i can't get it to work. I add the following to my Global.asax file:</p>
  
  <pre><code>    protected void Application_Error(object sender, EventArgs e)
      {
          Exception objErr = Server.GetLastError().GetBaseException();
          Session["Test"] = "Message:" + objErr.Message.ToString();
      }
  </code></pre>
  
  <p>(The Session is only for tests. Im gonna use a database to log error, if i get this to work.)
  Then i try to throw an exception from my HomeController and my Home/Index View, but it only triggers Debug.</p>
  
  <pre><code>    public ActionResult Index()
      {
          ViewData["Message"] = "Welcome to ASP.NET MVC!";
          throw (new Exception());
          return View();
      }
  </code></pre>
  
  <p>In my Webconfig file i set a defaulterror page but it doesn't redirect to the view:</p>
  
  <pre><code>    &lt;customErrors defaultRedirect="Home/Error"&gt;
          &lt;error statusCode="403" redirect="NoAccess.htm" /&gt;
          &lt;error statusCode="404" redirect="FileNotFound.htm" /&gt;
      &lt;/customErrors&gt;
  </code></pre>