コード例 #1
0
        /// <summary> Поиск вьюшки. Метод вызывает Startup.cs через DI.</summary>
        public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
        {
            // получаем путь где лежат все view-шки (корневая папка)
            var rootPath = $"{Configuration["ViewRootPath_Release"]}"; // для релиза путь такой т.к. при релизе не сохраняется структура папок

            #if DEBUG
            rootPath = $"..\\{Configuration["ViewAssembly_Debug"]}/{Configuration["ViewRootPath_Debug"]}";
            #endif

            // получаем имя контроллера вызвавшего вьюшку, чтобы выснить в какой папке нам искать вьюшку
            var controllerName = NormalizedRouteValue.GetNormalizedRouteValue(context, ControllerKey);

            // если не пришел viewName, то берем сами метод контроллера, что вызвал IActionResult
            viewName = String.IsNullOrEmpty(viewName) ? context.RouteData.Values["action"].ToString() : viewName;

            // формируем конечный путь поиска вьюшки
            string viewPath = $"{rootPath}/{controllerName}/{viewName}.html";

            if (File.Exists(viewPath))
            {
                return(ViewEngineResult.Found(viewPath, new PageGenerator(viewPath)));
            }
            else
            {
                return(ViewEngineResult.NotFound(viewName, new string[] { viewPath }));
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <inheritdoc/>
        public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (viewName == null)
            {
                throw new ArgumentNullException(nameof(viewName));
            }
            var controllerName = NormalizedRouteValue.GetNormalizedRouteValue(context, "controller");
            var path           = controllerName + "/" + viewName;

            if (!_views.TryGetValue(path, out var value))
            {
                return(ViewEngineResult.NotFound(path, new[] { "EightyCompiledViews/" + path }));
            }
            return(ViewEngineResult.Found(path, value(_serviceProvider)));
        }
コード例 #5
0
 public static string GetNormalizedRouteValue(ActionContext context, string key)
 => NormalizedRouteValue.GetNormalizedRouteValue(context, key);