Friday, March 18, 2016

web form error page in MVC!

This blog posting suggests you have to spec a web forms page for a custom error page in MVC app by putting something like so in the system.web stuff at Web.config!

<customErrors mode="On" defaultRedirect="404.aspx"/>

 
 

This will suffice for uncaught exceptions thrown in .NET itself. I tested it and it worked for me. There is some dirtiness in which the web form will return a 200 OK header, but I think you may fight your way out of this wet paper bag like so:

<% Response.StatusCode = 404; %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="404.aspx.cs"
      Inherits="Airport.Mvc._404" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
      <title></title>
   </head>
   <body>
      <form id="form1" runat="server">
         <div>Whoa! Oh no!</div>
      </form>
   </body>
</html>

 
 

The blog posting also suggests putting something like this in the system.webServer stuff at Web.config to catch errors thrown in IIS (as opposed to .NET exceptions).

<httpErrors errorMode="Custom">
   <remove statusCode="404"/>
   <error statusCode="404" path="404.aspx" responseMode="File"/>
</httpErrors>

 
 

...but when I try this I see the error page interpreted as if a .txt file splashing what you see in the middle of this blog posting, angle brackets and all, up to the user to see. Maybe this is because I am running Visual Studio locally and getting the extra variable of using Cassini or IIS Express or whatever it is. I dunno.

No comments:

Post a Comment