当前位置: 首页>>代码示例>>C#>>正文


C# ViewContext.GetRoutingInfo方法代码示例

本文整理汇总了C#中System.Web.Mvc.ViewContext.GetRoutingInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ViewContext.GetRoutingInfo方法的具体用法?C# ViewContext.GetRoutingInfo怎么用?C# ViewContext.GetRoutingInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.ViewContext的用法示例。


在下文中一共展示了ViewContext.GetRoutingInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Resolve

        public virtual string Resolve(ViewContext viewContext, string baseUrl, string entryPointRoot)
        {
            var routingInfo = viewContext.GetRoutingInfo();
            var rootUrl = string.Empty;
            var withBaseUrl = true;
            var server = viewContext.HttpContext.Server;

            if (String.IsNullOrWhiteSpace(entryPointRoot))
            {
                entryPointRoot = baseUrl;
            }

            var resolvedBaseUrl = UrlHelper.GenerateContentUrl(baseUrl, viewContext.HttpContext);
            var resolvedEntryPointRoot = UrlHelper.GenerateContentUrl(entryPointRoot, viewContext.HttpContext);

            if (resolvedEntryPointRoot != resolvedBaseUrl)
            {
                // entryPointRoot is different from default.
                if ((entryPointRoot.StartsWith("~") || entryPointRoot.StartsWith("/")))
                {
                    // entryPointRoot is defined as root relative, do not use with baseUrl
                    withBaseUrl = false;
                    rootUrl = resolvedEntryPointRoot;
                }
                else
                {
                    // entryPointRoot is defined relative to baseUrl; prepend baseUrl
                    resolvedEntryPointRoot = resolvedBaseUrl + entryPointRoot;
                }
            }

            var entryPointTemplates = new[]
            {
                "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Action,
                "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Controller + "-" + routingInfo.Action
            };

            var areas = new[]
            {
                routingInfo.Area,
                DefaultArea
            };

            foreach (var entryPointTmpl in entryPointTemplates)
            {
                foreach (var area in areas)
                {
                    var entryPoint = string.Format(entryPointTmpl, area).ToModuleName();
                    var filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

                    if (File.Exists(filePath))
                    {
                        var computedEntry = GetEntryPoint(server, filePath, baseUrl);
                        return withBaseUrl ? computedEntry : rootUrl + computedEntry;
                    }
                }
            }

            return null;
        }
开发者ID:vtfuture,项目名称:RequireJSDotNet,代码行数:60,代码来源:DefaultEntryPointResolver.cs

示例2: Resolve

        public string Resolve(ViewContext viewContext, string entryPointRoot)
        {
            var routingInfo = viewContext.GetRoutingInfo();
            var rootUrl = string.Empty;
            var withBaseUrl = true;
            var server = viewContext.HttpContext.Server;

            if (entryPointRoot != DefaultEntryPointRoot)
            {
                withBaseUrl = false;
                rootUrl = UrlHelper.GenerateContentUrl(entryPointRoot, viewContext.HttpContext);
            }

            // search for controller/action.js in current area
            var entryPointTmpl = "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Action;
            var entryPoint = string.Format(entryPointTmpl, routingInfo.Area).ToModuleName();
            var filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, entryPointRoot);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            // search for controller/action.js in common area
            entryPoint = string.Format(entryPointTmpl, DefaultArea).ToModuleName();
            filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, entryPointRoot);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            // search for controller/controller-action.js in current area
            entryPointTmpl = "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Controller + "-" + routingInfo.Action;
            entryPoint = string.Format(entryPointTmpl, routingInfo.Area).ToModuleName();
            filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, entryPointRoot);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            // search for controller/controller-action.js in common area
            entryPoint = string.Format(entryPointTmpl, DefaultArea).ToModuleName();
            filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, entryPointRoot);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            return null;
        }
开发者ID:philipooo,项目名称:RequireJSDotNet,代码行数:57,代码来源:DefaultEntryPointResolver.cs

示例3: Resolve

        public virtual string Resolve(ViewContext viewContext, string baseUrl, string entryPointRoot)
        {
            var routingInfo = viewContext.GetRoutingInfo();
            var rootUrl = string.Empty;
            var withBaseUrl = true;
            var server = viewContext.HttpContext.Server;

            if (entryPointRoot != DefaultEntryPointRoot)
            {
                // entryPointRoot is different from default.
                if ((entryPointRoot.StartsWith("~") || entryPointRoot.StartsWith("/")))
                {
                    // entryPointRoot is defined as root relative, do not use with baseUrl
                    withBaseUrl = false;
                    rootUrl = UrlHelper.GenerateContentUrl(entryPointRoot, viewContext.HttpContext);
                }
                else
                {
                    // entryPointRoot is defined relative to baseUrl; prepend baseUrl
                    entryPointRoot = baseUrl + entryPointRoot;
                }
            }

            // search for controller/action.js in current area
            var entryPointTmpl = "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Action;
            var entryPoint = string.Format(entryPointTmpl, routingInfo.Area).ToModuleName();
            var filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, baseUrl);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            // search for controller/action.js in common area
            entryPoint = string.Format(entryPointTmpl, DefaultArea).ToModuleName();
            filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, baseUrl);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            // search for controller/controller-action.js in current area
            entryPointTmpl = "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Controller + "-" + routingInfo.Action;
            entryPoint = string.Format(entryPointTmpl, routingInfo.Area).ToModuleName();
            filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, baseUrl);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            // search for controller/controller-action.js in common area
            entryPoint = string.Format(entryPointTmpl, DefaultArea).ToModuleName();
            filePath = server.MapPath(entryPointRoot + entryPoint + ".js");

            if (File.Exists(filePath))
            {
                var computedEntry = GetEntryPoint(server, filePath, baseUrl);
                return withBaseUrl ? computedEntry : rootUrl + computedEntry;
            }

            return null;
        }
开发者ID:segilbert,项目名称:RequireJSDotNet,代码行数:67,代码来源:DefaultEntryPointResolver.cs


注:本文中的System.Web.Mvc.ViewContext.GetRoutingInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。