zoukankan      html  css  js  c++  java
  • asp.net中的n种path

    在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.aspx?x=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是一个很强大的工具,可以帮助我们获取很多client和web宿主的信息,有兴趣的朋友可以通过以下代码看看它到底包含什么信息
            foreach (string s in Request.ServerVariables)
            {
                Response.Write(s 
    + "  :  " + Request.ServerVariables[s] + "<br /><br />");
            }

    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 
  • 相关阅读:
    使用MobaXterm远程连接Ubuntu,启动Octave,界面不能正常显示
    ABP .Net Core 日志组件集成使用NLog
    ABP .Net Core Entity Framework迁移使用MySql数据库
    ABP前端使用阿里云angular2 UI框架NG-ZORRO分享
    阿里云 Angular 2 UI框架 NG-ZORRO介绍
    Visual Studio 2019 Window Form 本地打包发布猫腻
    VS Code + NWJS(Node-Webkit)0.14.7 + SQLite3 + Angular6 构建跨平台桌面应用
    ABP .Net Core 调用异步方法抛异常A second operation started on this context before a previous asynchronous operation completed
    ABP .Net Core To Json序列化配置
    .Net EF Core数据库使用SQL server 2008 R2分页报错How to avoid the “Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement.”
  • 原文地址:https://www.cnblogs.com/ycdx2001/p/1545953.html
Copyright © 2011-2022 走看看