When is the MasterPageFile property of a view/page checked that it exists in ASP.NET MVC WebForms view engine?
What I want to do is have the following code not output the error:
Parser Error Message: The file '/SomePlaceThatDosentExist/Site.Master' does not exist.
Defined as such in my view's .aspx file:
<%@ Page Language="C#" MasterPageFile="~/SomePlaceThatDosentExist/Site.Master" Inherits="System.Web.Mvc.ViewPage" >
Where would I need to write some code to go in and define a valid MasterPageFile property?
I have tried the following in my custom ViewPage class that my views inherit
public override string MasterPageFile
{
get
{
return base.MasterPageFile;
}
set
{
base.MasterPageFile = "~/RealPlace/Site.Master";
}
}
and tried the following also (in a custom view page class that my views inherit)
protected override void OnPreInit(EventArgs e)
{
base.MasterPageFile = "~/RealPlace/Site.Master";
base.OnPreInit(e);
}
In both cases, the error I stated above is displayed.
From what I know, OnPreInit is the earliest point in a ViewPage's lifecycle, so is it possible to go even earlier in the lifecycle?
Note before you write and answer:
- I know about return View("ViewName", "MasterPageName");
- I know about dynamic master pages, but I want to accomplish this specific task