1. first take a look at the webformviewengine constructor: public WebFormViewEngine ()
{
Base. MasterLocationFormats = new string [] {"~ /Views/{1}/{0}. master ","~ /Views/Shared/{0}. master "};
Base. ViewLocationFormats = new string [] {"~ /Views/{1}/{0}. aspx ","~ /Views/{1}/{0}. ascx ","~ /Views/Shared/{0}. aspx ","~ /Views/Shared/{0}. ascx "};
Base. PartialViewLocationFormats = base. ViewLocationFormats;
}
Base. ViewLocationFormats can see why view pages can only be written in the views folder. Therefore, you only need to modify the base. ViewLocationFormats path in the new view engine constructor.
2. The following is a custom View Engine -- skinsuppviewviewengine, which must inherit from WebFormViewEngine.
Public class skinsuppviewviewengine: WebFormViewEngine
{
Public skinsuppviewviewengine ()
{
String [] mastersLocation = new []
{
String. Format ("~ /Skins/{0}/{0}. master ",
Utils. SkinName)
};
MasterLocationFormats = this. AddNewLocationFormats (new List <string> (MasterLocationFormats ),
MastersLocation );
String [] viewsLocation = new []
{
String. Format ("~ /Skins/{0}/Views/{1}/{0}. aspx ",
Utils. SkinName ),
String. Format ("~ /Skins/{0}/Views/{1}/{0}. ascx ",
Utils. SkinName)
};
ViewLocationFormats =
PartialViewLocationFormats = this. AddNewLocationFormats (new List <string> (ViewLocationFormats ),
ViewsLocation );
}
......
}
3. register a new View Engine in the Global File.
ViewEngines. Engines. Clear ();
ViewEngines. Engines. Add (new skinsuppviewviewengine ());