ASP.NET Core MVC 修改视图的默认路径及其实现原理解(4)

private ViewLocationCacheResult LocatePageFromViewLocations( ActionContext actionContext, string pageName, bool isMainPage) { var controllerName = GetNormalizedRouteValue(actionContext, ControllerKey); var areaName = GetNormalizedRouteValue(actionContext, AreaKey); string razorPageName = null; if (actionContext.ActionDescriptor.RouteValues.ContainsKey(PageKey)) { // Only calculate the Razor Page name if "page" is registered in RouteValues. razorPageName = GetNormalizedRouteValue(actionContext, PageKey); } var expanderContext = new ViewLocationExpanderContext( actionContext, pageName, controllerName, areaName, razorPageName, isMainPage); Dictionary<string, string> expanderValues = null; var expanders = _options.ViewLocationExpanders; // Read interface .Count once rather than per iteration var expandersCount = expanders.Count; if (expandersCount > 0) { expanderValues = new Dictionary<string, string>(StringComparer.Ordinal); expanderContext.Values = expanderValues; // Perf: Avoid allocations for (var i = 0; i < expandersCount; i++) { expanders[i].PopulateValues(expanderContext); } } var cacheKey = new ViewLocationCacheKey( expanderContext.ViewName, expanderContext.ControllerName, expanderContext.AreaName, expanderContext.PageName, expanderContext.IsMainPage, expanderValues); if (!ViewLookupCache.TryGetValue(cacheKey, out ViewLocationCacheResult cacheResult)) { _logger.ViewLookupCacheMiss(cacheKey.ViewName, cacheKey.ControllerName); cacheResult = OnCacheMiss(expanderContext, cacheKey); } else { _logger.ViewLookupCacheHit(cacheKey.ViewName, cacheKey.ControllerName); } return cacheResult; }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwwpzg.html