本文整理汇总了C#中System.Web.Routing.RouteBase.GetVirtualPath方法的典型用法代码示例。如果您正苦于以下问题:C# RouteBase.GetVirtualPath方法的具体用法?C# RouteBase.GetVirtualPath怎么用?C# RouteBase.GetVirtualPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Routing.RouteBase
的用法示例。
在下文中一共展示了RouteBase.GetVirtualPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetURL
internal static string GetURL(RouteBase route, RequestContext context, IResource resource)
{
var location = resource.Location;
var values = new RouteValueDictionary();
if (location is TypeLocation)
{
TypeLocation tl = location as TypeLocation;
values.Add("assembly", tl.ProxyType.Assembly.GetName().Name);
values.Add("name", tl.ProxyType.FullName);
}
else if (location is EmbeddedLocation)
{
EmbeddedLocation el = location as EmbeddedLocation;
values.Add("assembly", el.Assembly.GetName().Name);
values.Add("name", el.ResourceName);
}
else if (location is VirtualPathLocation)
{
VirtualPathLocation vl = location as VirtualPathLocation;
if (!(resource is IProxyResource))
return UrlHelper.GenerateContentUrl(vl.VirtualPath, context.HttpContext);
var p = vl.VirtualPath;
if (p[0] == '/') p = p.Substring(1);
values.Add("name", p);
}
else if (location is ExternalLocation)
{
ExternalLocation el = location as ExternalLocation;
return el.Uri.ToString();
}
else
throw new Exception("Unknown IResourceLocationType");
var pr = resource as IProxyResource;
if (pr != null && (pr.CultureSensitive || pr.CultureUISensitive))
{
if (pr.CultureSensitive)
values.Add("culture", CultureInfo.CurrentCulture.LCID.ToString("x"));
if (pr.CultureUISensitive)
values.Add("cultureUI", CultureInfo.CurrentUICulture.LCID.ToString("x"));
}
values.Add("version", ToHex(resource.Version));
var virtualPath = route.GetVirtualPath(context, values);
if (virtualPath == null) throw new Exception("Routing is incomplete.");
var url = UrlHelper.GenerateContentUrl("~/" + virtualPath.VirtualPath, context.HttpContext);
return url;
}
示例2: GetRoutedUrl
private string GetRoutedUrl(RouteBase route, RouteValueDictionary routeValues, RequestContext requestContext)
{
string routedVirtualPath = route.GetVirtualPath(requestContext, routeValues).VirtualPath; // i.e. "AllenISD"
// Get the base URL with the trailing slash, if it exists
string urlBase = requestUrlBaseProvider.GetRequestUrlBase(requestContext.HttpContext.Request);
// Construct the URL that has been regenerated (i.e. a request for https://app/AllenISD/Overview will be shortened
// to https://app/AllenISD if "Overview" is defaulted, thereby making it possible to match with generated URLs on
// the menu items for determining correct menu selection)
var returnValue = (new Uri(urlBase + routedVirtualPath)).AbsolutePath;
return returnValue;
}