Reputation: 10193
I have setup ELMAH in my MVC application and I want to display a friendly scren if an exception is thrown. However I still get the YSOD. So in my web.config I have (I have also tried the other modes with no success). My error controller has namespace ITOF.Controllers { using System.Net; using System.Web.Mvc;
public class ErrorController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult Unknown()
{
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return View("Unknown");
}
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult NotFound(string path)
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View("NotFound", path);
}
}
}
These methods get called when the mode="On"
However I then get a Runtime Error YSOD which tells me to change my web.config customError mode="RemoteOnly"
Maybe there is an error in my Views?
Here they are;
Unknown.cshtml;
@{
ViewBag.Title = "Error";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Sorry, an error occurred while processing your request.</h2>
NotFound.cshtml;
@{
ViewBag.Title = "Not Found";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Lost?</h2>
<p>Sorry - your request doesn't exist or was deleted.</p>
Upvotes: 2
Views: 91
Reputation: 1038830
In your NotFound
action you should be returning:
return View("NotFound", (object)path);
Notice how I am casting the second parameter to object in order to use the correct overload of the method. Otherwise you are calling the overload where the second argument represents a masterpage name.
Upvotes: 3