views:

150

answers:

1

I have a custom Error.aspx page in my ASP.NET MVC application. The error page uses a master page (which in turn uses another master page), and in the master page there is a call to HtmlHelper:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Unsecure.Master" ... %>
...
Html.RenderPartial("LogOnUserControl")

My web.config is set up to use this error page for all errors:

<customErrors mode="RemoteOnly" defaultRedirect="/Views/Shared/Error.aspx" />

The trouble is that the Html property of the ViewMasterPage is null. My understanding is that this property is simply pulled from the ViewPage's Html property which is also null. Thus, any attempt to call a partial method against the HtmlHelper fails with a NullReferenceException.

Why is the HtmlHelper null?

A: 

Does your MasterPage Page Directive look like this:

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>  

without the Inherits attribute Html.* doesn't exist.

mark123
Also, the defaultRedirect should work with your routing and not point directly to the View file. <customErrors mode="RemoteOnly" defaultRedirect="/ErrorController/GeneralErrorAction" />
mark123
Mark, that was one path I was heading down. My guess was that it was the MVC framework that sets on the HtmlHelper on the page so that not going through a controller but hitting an ASPX directly bypassed that step. However, meanwhile, a co-worker has simply made our ASPX page "dumber" (which, in my opinion, is a good thing for a catch-all error page).
Trinition
And, FWIW, my master page does in inherit from ViewMasterPage.
Trinition