<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 黃小二 閱讀(755) 評論(0)  編輯  收藏 所屬分類: ASP.NET
    主站蜘蛛池模板: 18禁黄网站禁片免费观看不卡| 99久久免费国产精精品| 欧美在线看片A免费观看| 亚洲激情视频网站| 黄色成人免费网站| 中文字幕乱码亚洲无线三区| 成年轻人网站色免费看| 亚洲欧洲专线一区| 免费一级毛片在线播放| 日韩a毛片免费观看| 亚洲伊人成无码综合网| 黄色网站软件app在线观看免费| 国产亚洲成av人片在线观看 | 好看的亚洲黄色经典| 国产免费AV片在线观看| 亚洲综合无码一区二区| 可以免费看黄的网站| 亚洲youwu永久无码精品| 亚洲成av人片不卡无码久久| 久久99精品免费一区二区| 亚洲一区二区中文| www.999精品视频观看免费| 亚洲AV无码AV男人的天堂不卡| 亚洲Aⅴ无码一区二区二三区软件 亚洲AⅤ视频一区二区三区 | 免费一级大黄特色大片| 国产JIZZ中国JIZZ免费看| 亚洲大片在线观看| 成年午夜视频免费观看视频| 又粗又长又爽又长黄免费视频| 亚洲VA中文字幕无码毛片| 色窝窝免费一区二区三区| 男男黄GAY片免费网站WWW| 久久91亚洲人成电影网站| 免费观看AV片在线播放| 免费大片av手机看片| 91亚洲导航深夜福利| 亚洲Av无码乱码在线观看性色 | 两个人看的www免费高清| 亚洲AV综合色区无码二区偷拍 | 四虎成人精品一区二区免费网站| 一个人看的在线免费视频|