title: MVC custom error view issues when site is deployed
body: <p>I'm seeing weird issues once a site is deployed. I have specified a custom error controller &amp; view in the Global.asax.cs using the following:</p>
  
  <pre><code>    protected void Application_Error(object sender, EventArgs e)
      {
          var httpContext = ((MvcApplication)sender).Context;
          var currentController = " ";
          var currentAction = " ";
          var currentRouteData = RouteTable.Routes.GetRouteData(
              new HttpContextWrapper(httpContext));
  
          if (currentRouteData != null)
          {
              if (currentRouteData.Values["controller"] != null 
                  &amp;&amp; !String.IsNullOrEmpty(currentRouteData.Values["controller"].ToString()))
              {
                  currentController = currentRouteData.Values["controller"].ToString();
              }
  
              if (currentRouteData.Values["action"] != null 
                  &amp;&amp; !String.IsNullOrEmpty(currentRouteData.Values["action"].ToString()))
              {
                  currentAction = currentRouteData.Values["action"].ToString();
              }
          }
  
          var ex = Server.GetLastError();
          var controller = new ErrorController();
          var routeData = new RouteData();
          var action = "Index";
  
          if (ex is HttpException)
          {
              var httpEx = ex as HttpException;
  
              switch (httpEx.GetHttpCode())
              {
                  case 404:
                      action = "NotFound";
                      break;
  
                  // others if any
              }
          }
  
          if (ex is NisSessionExpiredException)
          {
              action = "SessionExpired";
          }
  
          httpContext.ClearError();
          httpContext.Response.Clear();
          httpContext.Response.StatusCode = ex is HttpException 
              ? ((HttpException)ex).GetHttpCode() 
              : 500;
          httpContext.Response.TrySkipIisCustomErrors = true;
  
          routeData.Values["controller"] = "Error";
          routeData.Values["action"] = action;
  
          controller.ViewData.Model = new HandleErrorInfo(ex, currentController, currentAction);
          ((IController)controller).Execute(
              new RequestContext(new HttpContextWrapper(httpContext), routeData));
      }
  </code></pre>
  
  <p>That works fine locally, but once deployed on a server, when an error occurs it again uses the specified controller &amp; action but it always returns:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: The view 'Error' or its master was
    not found or no view engine supports the searched locations. The
    following locations were searched: ~/Views/Draft/Error.aspx
    ~/Views/Draft/Error.ascx ~/Views/Shared/Error.aspx
    ~/Views/Shared/Error.ascx ~/Views/Draft/Error.cshtml
    ~/Views/Draft/Error.vbhtml ~/Views/Shared/Error.cshtml
    ~/Views/Shared/Error.vbhtml    at
    System.Web.Mvc.ViewResult.FindView(ControllerContext context)    at
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
    at
    System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;>c__DisplayClass25.b__22(IAsyncResult
    asyncResult)    at
    System.Web.Mvc.Controller.&lt;>c__DisplayClass1d.b__18(IAsyncResult
    asyncResult)    at
    System.Web.Mvc.Async.AsyncResultWrapper.&lt;>c__DisplayClass4.b__3(IAsyncResult
    ar)    at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult
    asyncResult)    at
    System.Web.Mvc.Async.AsyncResultWrapper.&lt;>c__DisplayClass4.b__3(IAsyncResult
    ar)    at
    System.Web.Mvc.MvcHandler.&lt;>c__DisplayClass8.b__3(IAsyncResult
    asyncResult)    at
    System.Web.Mvc.Async.AsyncResultWrapper.&lt;>c__DisplayClass4.b__3(IAsyncResult
    ar)    at
    System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    Boolean&amp; completedSynchronously)</p>
  </blockquote>
  
  <p>instead of the expected errors (as you can see above the error view is supposed to give me detailed information of what the thrown exception is and also a call stack). In my understanding this view should have never been invoked (and also it is never invoked locally).</p>