public string GetAbsolutePath(string executingFilePath, string pagePath) { if (string.IsNullOrEmpty(pagePath)) { // Path is not valid; no change required. return(pagePath); } if (IsApplicationRelativePath(pagePath)) { // An absolute path already; no change required. return(pagePath); } if (!IsRelativePath(pagePath)) { // A page name; no change required. return(pagePath); } if (string.IsNullOrEmpty(executingFilePath)) { // Given a relative path i.e. not yet application-relative (starting with "~/" or "/"), interpret // path relative to currently-executing view, if any. // Not yet executing a view. Start in app root. var absolutePath = "/" + pagePath; return(PublicViewEnginePath.ResolvePath(absolutePath)); } return(PublicViewEnginePath.CombinePath(executingFilePath, pagePath)); }
private PublicViewLocationCacheResult OnCacheMiss(ViewLocationExpanderContext expanderContext, PublicViewLocationCacheKey cacheKey) { var viewLocations = GetViewLocationFormats(expanderContext); var expanders = options.ViewLocationExpanders; // Read interface .Count once rather than per iteration var expandersCount = expanders.Count; for (var i = 0; i < expandersCount; i++) { viewLocations = expanders[i].ExpandViewLocations(expanderContext, viewLocations); } PublicViewLocationCacheResult cacheResult = null; var searchedLocations = new List <string>(); var expirationTokens = new HashSet <IChangeToken>(); foreach (var location in viewLocations) { var path = string.Format( CultureInfo.InvariantCulture, location, expanderContext.ViewName, expanderContext.ControllerName, expanderContext.AreaName); path = PublicViewEnginePath.ResolvePath(path); cacheResult = CreateCacheResult(expirationTokens, path, expanderContext.IsMainPage); if (cacheResult != null) { break; } searchedLocations.Add(path); } // No views were found at the specified location. Create a not found result. if (cacheResult == null) { cacheResult = new PublicViewLocationCacheResult(searchedLocations); } var cacheEntryOptions = new MemoryCacheEntryOptions(); cacheEntryOptions.SetSlidingExpiration(this.options.CacheExpirationDuration); foreach (var expirationToken in expirationTokens) { cacheEntryOptions.AddExpirationToken(expirationToken); } return(ViewLookupCache.Set(cacheKey, cacheResult, cacheEntryOptions)); }