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(ViewEnginePath.ResolvePath(absolutePath)); } return(ViewEnginePath.CombinePath(executingFilePath, pagePath)); }
public static bool IsCurrentPage(this ViewContext context, string pageName) { string normalizedRouteValue = NormalizedRouteValue.GetNormalizedRouteValue(context, "page"); string expectedPageValue = ViewEnginePath.CombinePath(normalizedRouteValue, pageName); RouteData routeData = context.HttpContext.GetRouteData(); var page = (string)routeData.Values["page"]; if (page == expectedPageValue) { return(true); } return(false); }
private static object CalculatePageName(ActionContext actionContext, 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] != '/') { var currentPagePath = NormalizedRouteValue.GetNormalizedRouteValue(actionContext, "page"); 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); }