ASP.NET中的n种路径

    技术2022-06-08  59

    web端开发中经常会遇到各种不同情势的path,而且经常记不明确如何获取到某种特定款式,今天抽了点光阴把常用的path获取法子 与款式做了一个简略的对照 表,以备日后查用。

    Request获取的信息

    Request.AppRelativeCurrentExecutionFilePath                  ~/SysOption/BillingSetup1.aspx

    Request.ApplicationPath                                                 /

    Request.CurrentExecutionFilePath                                   /SysOption/BillingSetup1.aspx

    Request.FilePath                                                            /SysOption/BillingSetup1.aspx

    Request.Path                                                                /SysOption/BillingSetup1.aspx

    Request.PathInfo                                                          什么都没有(待测其他用法)

    Request.PhysicalApplicationPath                               D:/VssWorkFolder/British_School_MIS/src/WebSite/

    Request.PhysicalPath                                                      D:/VssWorkFolder/British_School_MIS/src/WebSite/SysOption/BillingSetup1.aspx

    Request.UserHostAddress                                              192.168.1.6

    Request.UserHostName                                                  192.168.1.6

    Request.Url.ToString()                                                    http://192.168.1.6/SysOption/BillingSetup1.aspxx=d

    Request.UrlReferrer                                                        空引用或者跳转源页面地址        

     

    Request.ServerVariables聚拢中获取到的相干信息:

    左列是变量名,右侧是值,值是通过Request.ServerVariables[服务器变量名]获取的

    APPL_MD_PATH : /LM/W3SVC/894523/Root

    APPL_PHYSICAL_PATH : D:/VssWorkFolder/British_School_MIS/src/WebSite/

    INSTANCE_META_PATH : /LM/W3SVC/894523

    LOCAL_ADDR : 192.168.1.6

    PATH_INFO : /SysOption/BillingSetup1.aspx

    PATH_TRANSLATED : D:/VssWorkFolder/British_School_MIS/src/WebSite/SysOption/BillingSetup1.aspx

    REMOTE_ADDR : 192.168.1.6

    REMOTE_HOST : 192.168.1.6

    SCRIPT_NAME : /SysOption/BillingSetup1.aspx

    SERVER_NAME : 192.168.1.6

    URL : /SysOption/BillingSetup1.aspx

    Request.ServerVariables是一个很强大的工具,可以赞助 我们获取很多clientweb宿主的信息,有兴趣 的朋友可以通过以下代码看看它到底包孕什么信息

            foreach (string s in Request.ServerVariables)

            {

                Response.Write(s + "  :  " + Request.ServerVariables[s] + "");

            }

    path转换

    1.转换为服务器端路径(Server.MapPath

    web服务器端开发设计一个有趣的问题就是,地址转换。比如http地址/images/a.txt,如果你想在服务器端通过io读取这个文件,就得有这个文件的“本机地址(形如c:/windows/system32/xx.dll)”,这时Server.MapPath就很有用了

    Response.Write(Request.MapPath(Request.Path));        输出为 D:/VssWorkFolder/British_School_MIS/src/WebSite/SysOption/BillingSetup1.aspx

    2.转换为http地址(Page.ResolveClientUrl Page.ResolveUrl

    Response.Write(Page.ResolveClientUrl("~/a/a.jpg"));      输出为 ../a/a.jpg

    Response.Write(Page.ResolveUrl("~/a/a.jpg"));              输出为 /a/a.jpg


    最新回复(0)