Я предлагаю вам использовать специализированный ViewEngine с некоторыми пользовательскими местами поиска. Поскольку вы все еще используете страницы WebForms, вы можете просто извлечь из встроенного WebFormViewEngine:
public class ThemedViewEngine : WebFormViewEngine {
private static readonly string[] _emptyLocations = new string[0];
//Format: {0} page name {1} controller {2} design
string[] _masterLocations = new[] {
"~/Views/{2}/{0}.master"
};
string[] _viewLocations = new[] {
"~/Views/{2}/{1}/{0}.aspx",
"~/Views/{2}/Shared/{0}.aspx",
};
#region View search
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) {
string[] viewLocationsSearched;
string[] masterLocationsSearched;
string viewPath = FindPath(controllerContext, _viewLocations, viewName, _cacheKeyPrefix_View, useCache, out viewLocationsSearched);
string masterPath = FindPath(controllerContext, _masterLocations, masterName, _cacheKeyPrefix_Master, useCache, out masterLocationsSearched);
//Check if one view missing
if (String.IsNullOrEmpty(viewPath) || (String.IsNullOrEmpty(masterPath) && !String.IsNullOrEmpty(masterName))) {
return new ViewEngineResult(viewLocationsSearched.Union(masterLocationsSearched));
}
return new ViewEngineResult(CreateView(controllerContext, viewPath, masterPath), this);
}
//Same thing as above, but without master page
public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) {
string[] viewLocationsSearched;
string viewPath = FindPath(controllerContext, _viewLocations, partialViewName, _cacheKeyPrefix_Partial, useCache, out viewLocationsSearched);
if (String.IsNullOrEmpty(viewPath)) {
return new ViewEngineResult(viewLocationsSearched);
}
return new ViewEngineResult(CreatePartialView(controllerContext, viewPath), this);
}
protected string FindPath(ControllerContext context, string[] locations, string viewName, string prefix, bool useCache, out string[] searched) {
searched = _emptyLocations;
if (string.IsNullOrEmpty(viewName))
return string.Empty;
//Prepare your data here
string controllerName = context.RouteData.GetRequiredString("controller");
string designName = /* YOUR WAY OF GETTING THE DESIGN */;
string result = FindPathGeneral(context, locations, viewName, controllerName, designName, out searched);
return result;
}
/// <summary>
/// Finds the complete path for a general view page.
/// </summary>
private string FindPathGeneral(ControllerContext context, string[] locations, string viewName, string controllerName, string designName, out string[] searched) {
string result = string.Empty;
searched = new string[locations.Length];
for (int i = 0; i < locations.Length; i++) {
//Build virtual path from the locations defined on top
string virtualPath = String.Format(CultureInfo.InvariantCulture, locations[i],
viewName, controllerName, designName);
if (FileExists(context, virtualPath)) {
searched = _emptyLocations;
return virtualPath;
}
searched[i] = virtualPath;
}
return result;
}
#endregion
}
Это должно работать для вашего случая, при условии, что вы нашли способ найти нужное имя дизайна в методе FindPath
.
В приведенном выше примере не реализовано кэширование представлений для простоты. Вы можете проверить код WebFormViewEngine
с отражателем (или из исходного кода), чтобы увидеть, как это делается фреймворком.