ASP.NET 虚拟路径 /表示网站根目录../表示上级目录 ./表示当前目录 ~服务器端用的如果在服务器端空间中(使用runat=server的控件)会自动将“~”进行转换,如果在html控件或者需要在代码中转换的话可以使用VirtualPathUtility.ToAbsolute("~/a/b1.aspx")就是将虚拟路径转换为相对于应用根的全路径,也就是/WebSite4/a/b1.aspx
VirtualPathUtility类主要方法:string AppendTraiilingSlash(string virtualPath);如果路径virtualPath最后没有“/”则添加;string Combine(string basePath,string relativePath),将两个路径进行合并;string GetDirectory(string virtualPath),返回虚拟路径的目录部分;string MakeRelative(string fromPath,string toPath)计算两个虚拟路径的相对路径;ToAbsolute,转换为绝对路径
Request对象Request.AppRelativeCurrentExecutionFliePath,获得当前执行请求相对于应用目录的虚拟路径,以~开头如"~/Handler.ashx"Request.PhysicalApplicationPath,获取当前应用的物理物理路径,比如“D:\我的文档\Visual Studio2010\WebSite4\"Request.PhysicalPath,获取当前请求的物理路径,比如”D:\我的文档\Visual Studio2010\WebSite4\Handler.ashx“Request.RawUrl
下载文件:context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\" ", encodeFileName));能直接将生成的内容以流的形式输出给浏览器,就不要生成临时文件
ashx页面要用session需要调用IRequiresSessionState接口
转载于:https://www.cnblogs.com/blackHorseplan/p/3897729.html
相关资源:asp.net 获取路径的几种方式