本文整理汇总了C#中System.Web.HttpContextBase.ResolveUrl方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.ResolveUrl方法的具体用法?C# HttpContextBase.ResolveUrl怎么用?C# HttpContextBase.ResolveUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContextBase
的用法示例。
在下文中一共展示了HttpContextBase.ResolveUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveFilePath
/// <summary>
/// Resolves an absolute web path for the file path
/// </summary>
/// <param name="file"></param>
/// <param name="http"></param>
/// <returns></returns>
public static string ResolveFilePath(this IClientDependencyFile file, HttpContextBase http)
{
var trimmedPath = file.FilePath.Trim();
if (string.IsNullOrEmpty(trimmedPath))
{
throw new ArgumentException("The Path specified is null", "Path");
}
if (trimmedPath.StartsWith("~/"))
{
return http.ResolveUrl(file.FilePath);
}
if (trimmedPath.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|| trimmedPath.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
return file.FilePath;
}
var filePath = file.FilePath;
if (!http.IsAbsolute(filePath))
{
//get the relative path
var path = http.Request.AppRelativeCurrentExecutionFilePath.Substring(0, http.Request.AppRelativeCurrentExecutionFilePath.LastIndexOf('/') + 1);
filePath = http.ResolveUrl(path + filePath);
}
var uri = new Uri(new Uri("https://example.com"), filePath);
return uri.PathAndQuery;
}
示例2: ResolvePath
public static string ResolvePath(this IClientDependencyPath path, HttpContextBase http)
{
if (string.IsNullOrEmpty(path.Path))
{
throw new ArgumentException("The Path specified is null", "Path");
}
if (path.Path.StartsWith("~/"))
{
return http.ResolveUrl(path.Path);
}
return path.Path;
}