private static object CalculatePageName(ActionContext context, RouteValueDictionary ambientValues, string pageName) { Debug.Assert(pageName.Length > 0); // Paths not qualified with a leading slash are treated as relative to the current page. if (pageName[0] != '/') { // OK now we should get the best 'normalized' version of the page route value that we can. string currentPagePath; if (context != null) { currentPagePath = NormalizedRouteValue.GetNormalizedRouteValue(context, "page"); } else if (ambientValues != null) { currentPagePath = ambientValues["page"]?.ToString(); } else { currentPagePath = null; } if (string.IsNullOrEmpty(currentPagePath)) { // Disallow the use sibling page routing, a Razor page specific feature, from a non-page action. throw new InvalidOperationException(Resources.FormatUrlHelper_RelativePagePathIsNotSupported(pageName)); } return(ViewEnginePath.CombinePath(currentPagePath, pageName)); } return(pageName); }
private static object CalculatePageName(ActionContext context, RouteValueDictionary ambientValues, string pageName) { Debug.Assert(pageName.Length > 0); // Paths not qualified with a leading slash are treated as relative to the current page. if (pageName[0] != '/') { // OK now we should get the best 'normalized' version of the page route value that we can. string currentPagePath; if (context != null) { currentPagePath = NormalizedRouteValue.GetNormalizedRouteValue(context, "page"); } else if (ambientValues != null) { currentPagePath = Convert.ToString(ambientValues["page"], CultureInfo.InvariantCulture); } else { currentPagePath = null; } if (string.IsNullOrEmpty(currentPagePath)) { // Disallow the use sibling page routing, a Razor page specific feature, from a non-page action. // OR - this is a call from LinkGenerator where the HttpContext was not specified. // // We can't use a relative path in either case, because we don't know the base path. throw new InvalidOperationException(Resources.FormatUrlHelper_RelativePagePathIsNotSupported( pageName, nameof(LinkGenerator), nameof(HttpContext))); } return(ViewEnginePath.CombinePath(currentPagePath, pageName)); } return(pageName); }