熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET中的n種路徑

2022-06-13   來源: .NET編程 

  在web服務器端開發中經常會遇到各種不同形式的path而且經常記不清楚如何獲取到某種特定格式今天抽了點時間把常用的path獲取方法與格式做了一個簡單的對照表以備日後查用

  Request獲取的信息

  RequestAppRelativeCurrentExecutionFilePath                  ~/SysOption/BillingSetupaspx

  RequestApplicationPath                                                 /

  RequestCurrentExecutionFilePath                                   /SysOption/BillingSetupaspx

  RequestFilePath                                                            /SysOption/BillingSetupaspx

  RequestPath                                                                /SysOption/BillingSetupaspx

  RequestPathInfo                                                          什麼都沒有(待測其他用法)

  RequestPhysicalApplicationPath                               D:\VssWorkFolder\British_School_MIS\src\WebSite\

  RequestPhysicalPath                                                      D:\VssWorkFolder\British_School_MIS\src\WebSite\SysOption\BillingSetupaspx

  RequestUserHostAddress                                             

  RequestUserHostName                                                 

  RequestUrlToString()                                                    x?x=d

  RequestUrlReferrer                                                        空引用或者跳轉源頁面地址        

   

  RequestServerVariables集合中獲取到的相關信息:

  左列是服務器變量名右側是值值是通過RequestServerVariables[服務器變量名]獲取的

  APPL_MD_PATH : /LM/WSVC//Root

  APPL_PHYSICAL_PATH : D:\VssWorkFolder\British_School_MIS\src\WebSite\

  INSTANCE_META_PATH : /LM/WSVC/

  LOCAL_ADDR :

  PATH_INFO : /SysOption/BillingSetupaspx

  PATH_TRANSLATED : D:\VssWorkFolder\British_School_MIS\src\WebSite\SysOption\BillingSetupaspx

  REMOTE_ADDR :

  REMOTE_HOST :

  SCRIPT_NAME : /SysOption/BillingSetupaspx

  SERVER_NAME :

  URL : /SysOption/BillingSetupaspx

  RequestServerVariables是一個很強大的工具可以幫助我們獲取很多client和web宿主的信息有興趣的朋友可以通過以下代碼看看它到底包含什麼信息

  foreach (string s in RequestServerVariables)

  {

  ResponseWrite(s +   :  + RequestServerVariables[s] + );

  }

  path轉換

  轉換為服務器端路徑(ServerMapPath)

  web服務器端開發設計一個有趣的問題就是地址轉換比如http地址/images/atxt如果你想在服務器端通過io讀取這個文件就得有這個文件的本機地址(形如c:\windows\system\xxdll)這時ServerMapPath就很有用了

  ResponseWrite(RequestMapPath(RequestPath));        輸出為 D:\VssWorkFolder\British_School_MIS\src\WebSite\SysOption\BillingSetupaspx

  轉換為http地址(PageResolveClientUrl PageResolveUrl)

  ResponseWrite(PageResolveClientUrl(~/a/ajpg));      輸出為 /a/ajpg

  ResponseWrite(PageResolveUrl(~/a/ajpg));              輸出為 /a/ajpg


From:http://tw.wingwit.com/Article/program/net/201311/13233.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.