<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-7  評論-24  文章-102  trackbacks-0


    引用自:
    asp.net獲取網站路徑
    http://hi.baidu.com/zhangfengbang/blog/item/5f99d74b0ce661f883025cbc.html
    HttpRequest 成員
    http://msdn.microsoft.com/zh-cn/library/system.web.httprequest_members(v=VS.80).aspx
    ASP.NET獲取網站根目錄的url的函數,很簡單
    http://www.xueit.com/html/2009-03/21_932_00.html
     



    網站在服務器磁盤上的物理路徑: HttpRuntime.AppDomainAppPath
    虛擬程序路徑: HttpRuntime.AppDomainAppVirtualPath


    任何于Request/HttpContext.Current等相關的方法, 都只能在有請求上下文或者頁面時使用. 即在無請求上下文時,HttpContext.Current為null. 而上面提到的方法一直可用.

    對于全局Cache對象的訪問亦然.



    示例:輸出asp.net 網站路徑。 

    private void responseHtml()
        {
             System.Text.StringBuilder sb 
    = new System.Text.StringBuilder();
      
    //輸出:當前時間: 2007-08-30 11:03:49
             sb.Append(string.Format("當前時間: {0}", Server.HtmlEncode(DateTime.Now.ToString())));
             sb.Append(
    "<br />");

      
    //當前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
             sb.Append(string.Format("當前請求的虛擬路徑: {0}",Server.HtmlEncode(Request.CurrentExecutionFilePath)));
             sb.Append(
    "<br />");

      
    //獲取當前應用程序的根目錄路徑: /aDirectory
             sb.Append(string.Format("獲取當前應用程序的根目錄路徑: {0}", Server.HtmlEncode(Request.ApplicationPath)));
             sb.Append(
    "<br />");

      
    //當前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
             sb.Append(string.Format("當前請求的虛擬路徑: {0}",Server.HtmlEncode(Request.FilePath)));
             sb.Append(
    "<br />");

      
    //當前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
             sb.Append(string.Format("當前請求的虛擬路徑: {0}",Server.HtmlEncode(Request.Path)));
             sb.Append(
    "<br />");

      
    //獲取當前正在執行的應用程序的根目錄的物理文件系統路徑: E:\Visual Studio 2005\
             sb.Append(string.Format("獲取當前正在執行的應用程序的根目錄的物理文件系統路徑: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
             sb.Append(
    "<br />");

      
    //獲取與請求的 URL 相對應的物理文件系統路徑: E:\Visual Studio 2005\\aDirectory\
             sb.Append(string.Format("獲取與請求的 URL 相對應的物理文件系統路徑: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
             sb.Append(
    "<br />");
             Response.Write(sb.ToString());
         }

     



    在ASP.NET編程中經常需要用Request獲取url的有關信息.

    測試的url地址是http://www.test.com/testweb/default.aspx, 結果如下:
    Request.ApplicationPath:                     /testweb
    Request.CurrentExecutionFilePath:       /testweb/default.aspx
    Request.FilePath:                                /testweb/default.aspx
    Request.Path:                                     /testweb/default.aspx
    Request.PathInfo:
    Request.PhysicalApplicationPath:          E:\WWW\testweb\
    Request.PhysicalPath:                         E:\WWW\testweb\default.aspx
    Request.RawUrl:                                 /testweb/default.aspx
    Request.Url.AbsolutePath:                    /testweb/default.aspx
    Request.Url.AbsoluteUri:                      http://www.test.com/testweb/default.aspx
    Request.Url.Host:                                www.test.com
    Request.Url.LocalPath:                        /testweb/default.aspx 

    當url中帶參數時可以使用:
    HttpContext.Current.Request.Url.PathAndQuery.ToString()//

    本頁地址:   Request.URL; 

    上頁地址:  
    Request.UrlReferrer  
    Request.ServerViables["http_referer"]  
    Request.RawUrl  
    Request.RawUrl.QueryAndPath  
    System.IO.Path.GetFileName(Request.FilePath.ToString()) 




    獲取網站根目錄的url源代碼--2010.05.09
    http://www.xueit.com/html/2009-03/21_932_00.html

    public static string GetRootURI()
        {
            
    string AppPath = "";
            HttpContext HttpCurrent 
    = HttpContext.Current;
            HttpRequest Req;
            
    if (HttpCurrent != null)
            {
                Req 
    = HttpCurrent.Request;
                
    string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
                
    if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
                    
    //直接安裝在   Web   站點   
                    AppPath = UrlAuthority;
                
    else
                    
    //安裝在虛擬子目錄下   
                    AppPath = UrlAuthority + Req.ApplicationPath;
            }
            
    return AppPath;
        }

    可修改為靜態屬性 

    private
     static string rootURI;

        
    /// <summary>
        
    /// 獲得網站根目錄的url的函數
        
    /// </summary>
        
    /// <returns>應用程序根目錄 eg:  http://www.xxx.net:2156/im </returns>
        public static string RootURI
        {
            
    get
            {
                
    if (string.IsNullOrEmpty(rootURI))
                {
                    HttpContext HttpCurrent 
    = HttpContext.Current;
                    HttpRequest Req;
                    
    if (HttpCurrent != null)
                    {
                        Req 
    = HttpCurrent.Request;

                        
    string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
                        
    if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
                            
    //直接安裝在   Web   站點   
                            rootURI = UrlAuthority;
                        
    else
                            
    //安裝在虛擬子目錄下   
                            rootURI = UrlAuthority + Req.ApplicationPath;
                    }
                }

                
    return rootURI;
            }
        }

    posted on 2010-05-09 00:02 黃小二 閱讀(762) 評論(0)  編輯  收藏 所屬分類: ASP.NET
    主站蜘蛛池模板: 114级毛片免费观看| 深夜久久AAAAA级毛片免费看| 在线播放免费人成毛片乱码| 免费大香伊蕉在人线国产| 亚洲欧美日韩综合久久久| 日韩欧美一区二区三区免费观看| 亚洲一级毛片在线播放| 国产情侣激情在线视频免费看| 亚洲精品免费在线| 久久精品国产免费观看| 亚洲中文字幕人成乱码| 成年人免费观看视频网站| 亚洲成av人片天堂网无码】| 国产又大又黑又粗免费视频| 激情吃奶吻胸免费视频xxxx| 国产精品亚洲不卡一区二区三区| 男女一进一出抽搐免费视频| 日韩亚洲一区二区三区| 最近2022中文字幕免费视频| 亚洲国产精品综合久久久| 在线视频免费观看www动漫| 美女被免费网站在线视频免费| 久久久久无码专区亚洲av| 久久精品无码精品免费专区| 亚洲另类精品xxxx人妖| 97无码免费人妻超级碰碰碰碰| 亚洲AV综合永久无码精品天堂| 国产不卡免费视频| 最新亚洲成av人免费看| 亚洲自偷精品视频自拍| 超pen个人视频国产免费观看| 性生大片视频免费观看一级| 久久久久亚洲AV成人无码网站| 在线精品一卡乱码免费| 免费大片黄在线观看| 亚洲精品成人av在线| 成人午夜18免费看| 手机看片国产免费永久| 国产午夜亚洲精品| 亚洲男人的天堂www| 国产福利在线观看免费第一福利|