Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 Custom error pages gives blank result
    primarykey
    data
    text
    <p>Using the blog posted <a href="http://blog.davebouwman.com/2011/04/21/custom-404-pages-for-asp-net-mvc-3/" rel="nofollow noreferrer">here</a> and a topic <a href="https://stackoverflow.com/questions/5226791/custom-error-pages-on-asp-net-mvc3">here</a> on SO i've created a controller which should handle all my error pages.</p> <p>In my Global.asax.cs I've got the following piece of code:</p> <pre><code>protected void Application_Error() { var exception = Server.GetLastError(); var httpException = exception as HttpException; var routeData = new RouteData(); Response.Clear(); Server.ClearError(); routeData.Values["controller"] = "Error"; routeData.Values["action"] = "General"; routeData.Values["exception"] = exception; Response.StatusCode = 500; if (httpException != null) { Response.StatusCode = httpException.GetHttpCode(); switch (Response.StatusCode) { case 403: routeData.Values["action"] = "Http403"; break; case 404: routeData.Values["action"] = "Http404"; break; } } // Avoid IIS7 getting in the middle Response.TrySkipIisCustomErrors = true; IController errorsController = new ErrorController(); HttpContextWrapper wrapper = new HttpContextWrapper(Context); var rc = new RequestContext(wrapper, routeData); errorsController.Execute(rc); } </code></pre> <p>My ErrorController looks like this:</p> <pre><code>public class ErrorController : BaseController { /// &lt;summary&gt; /// Returns a default view for not having access. /// &lt;/summary&gt; public ActionResult Unauthorized() { BaseModel viewModel = new BaseModel { LoginModel = new LogonModel(), ProfessionsTopX = GetTopXProfessions() }; return View(viewModel); } public ActionResult General(Exception exception) { return View("Exception", exception); } public ActionResult Http404() { //This line works //return Content("Not found", "text/plain"); //This line presents a blank page return View("404","_Layout"); } public ActionResult Http403() { return View("403", "_Layout"); } } </code></pre> <p>And my Razor View only contains the piece of html below;</p> <pre><code>@{ ViewBag.Title = "404"; } &lt;h2&gt;404&lt;/h2&gt; This is a 404 page! </code></pre> <p>When I use the Return Content i'm getting a plain textoutput telling me i'm looking at a 404-page. However, I want the 404 page to fit the rest of my design, so I want to use my own Views. However as soon as I use Return View I'm getting a blank page. I expect to be missing something very obvious, but I don't see it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload