本文整理汇总了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;
}
示例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;
}
示例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;
}