获取 ASP.NET 网站路径
示例:输出asp.net 网站路径。
private void responseHtml()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(string.Format("当前时间: {0}", Server.HtmlEncode(DateTime.Now.ToString())));
sb.Append("<br />");
sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.CurrentExecutionFilePath)));
sb.Append("<br />");
sb.Append(string.Format("获取当前应用程序的根目录路径: {0}", Server.HtmlEncode(Request.ApplicationPath)));
sb.Append("<br />");
sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.FilePath)));
sb.Append("<br />");
sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.Path)));
sb.Append("<br />");
sb.Append(string.Format("获取当前正在执行的应用程序的根目录的物理文件系统路径: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
sb.Append("<br />");
sb.Append(string.Format("获取与请求的 URL 相对应的物理文件系统路径: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
sb.Append("<br />");
Response.Write(sb.ToString());
}
}
输出:当前时间: 2007-08-30 11:03:49
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前应用程序的根目录路径: /aDirectory
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前正在执行的应用程序的根目录的物理文件系统路径: E:\Visual Studio 2005\
获取与请求的 URL 相对应的物理文件系统路径: E:\Visual Studio 2005\\aDirectory\
参考引用:http://msdn2.microsoft.com/zh-cn/library/ms178116(VS.80).aspx
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
输出:当前时间: 2007-08-30 11:03:49
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前应用程序的根目录路径: /aDirectory
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前正在执行的应用程序的根目录的物理文件系统路径: E:\Visual Studio 2005\
获取与请求的 URL 相对应的物理文件系统路径: E:\Visual Studio 2005\\aDirectory\
参考引用:http://msdn2.microsoft.com/zh-cn/library/ms178116(VS.80).aspx
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1765068