在ASP.NET中,如何将~/Application/Page.aspx转换为http://localhost:45/MyApp/Application/Page.aspx
基本上我想把虚拟路径转换成绝对路径 试试这个在ASP.NET中,如何将~/Application/Page.aspx转换为http://localhost:45/MyApp/Application/Page.aspx,asp.net,Asp.net,基本上我想把虚拟路径转换成绝对路径 试试这个 /// <summary> /// Return full path of the IIS application /// </summary> public string FullyQualifiedApplicationPath { get { //Getting the current context of HTTP request var context = HttpCo
/// <summary>
/// Return full path of the IIS application
/// </summary>
public string FullyQualifiedApplicationPath
{
get
{
//Getting the current context of HTTP request
var context = HttpContext.Current;
//Checking the current context content
if (context == null) return null;
//Formatting the fully qualified website url/name
var appPath = string.Format("{0}://{1}{2}{3}",
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port == 80
? string.Empty
: ":" + context.Request.Url.Port,
context.Request.ApplicationPath);
if (!appPath.EndsWith("/"))
appPath += "/";
return appPath;
}
}
//
///返回IIS应用程序的完整路径
///
公共字符串FullyQualifiedApplicationPath
{
得到
{
//获取HTTP请求的当前上下文
var context=HttpContext.Current;
//检查当前上下文内容
if(context==null)返回null;
//格式化完全限定的网站url/名称
var appPath=string.Format(“{0}://{1}{2}{3}”,
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port==80
?字符串。空
:“:”+context.Request.Url.Port,
context.Request.ApplicationPath);
如果(!appPath.EndsWith(“/”)
appPath+=“/”;
返回appPath;
}
}
工作起来很有魅力,只做了一点修改:私有静态字符串变为绝对(字符串相关){HttpContext context=HttpContext.Current;返回字符串.Format(“{0}://{1}{2}{3}”,context.Request.Url.Scheme,context.Request.Url.Host,context.Request.Url.Port==80?string.Empty:“:”+context.Request.Url.Port,VirtualPathUtility.ToAbsolute(AppRelative));}