views:

1302

answers:

3

Hi folks

I have the following HandleError filter on my controller:

[HandleError(ExceptionType = typeof(ArgumentException), View = "DestinationError")]

I've set-up the Web.Config so that customErrors are on. The problem I'm having is that the HandleError filter is working fine, when I run the app locally out of Visual Studio, but when I deploy it to the server all I get is a 500 Internal Server Error, indicating the Error view cannot be found.

Has anyone come across this before, I'm suspicious that routing may be the root cause of the problem (hoho). The site gets deployed into a directory in the web root, rather than into the wwwroot itself, so perhaps IIS cannot locate the error file.

Any help on this issue would be appreciated.

+3  A: 

To answer my own question the magic is to turn off HTTP Errors in IIS. I'm not delighted in this workaround, so if anyone has any better ideas, I'd love to hear them.

A: 

What if you try the following?

Response.TrySkipIisCustomErrors = true;
labilbe
+1  A: 

Otherwise you can use the Web.Config configuration and set it to the expected controller's actions. Like this:

    <customErrors mode="On" defaultRedirect="/Error">
        <error statusCode="404" redirect="/Error/NotFound"/>
    </customErrors>

Then imagine you have an Error controlller (/Error) which points out to an index action

public class ErrorController : Controller
{
    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index()
    {
        Response.StatusCode = (int)HttpStatusCode.InternalServerError;
        return View("Index");
    }

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult NotFound()
    {
        Response.StatusCode = (int)HttpStatusCode.NotFound;
        return View("NotFound");
    }
}
labilbe