<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
    主站蜘蛛池模板: 亚洲精品视频在线观看免费| 亚洲AV永久纯肉无码精品动漫| 亚洲国产成人精品青青草原| 免费视频成人片在线观看| 亚洲综合国产一区二区三区| h视频在线免费观看| 亚洲美女又黄又爽在线观看| 99久久99这里只有免费的精品| 亚洲日本韩国在线| baoyu777永久免费视频| 亚洲无线码一区二区三区| 成在人线av无码免费高潮喷水| 国产∨亚洲V天堂无码久久久| 国产一精品一AV一免费| 亚洲黄色高清视频| 曰曰鲁夜夜免费播放视频 | 亚洲欧洲日韩不卡| 99久久综合精品免费| 亚洲精品网站在线观看你懂的| 7723日本高清完整版免费| 美女视频黄免费亚洲| 美女无遮挡拍拍拍免费视频 | 丝袜足液精子免费视频| 中文字幕亚洲无线码| 另类免费视频一区二区在线观看| 亚洲成人免费在线| 一二三四免费观看在线电影| 亚洲精品久久无码| 国产亚洲精品精品国产亚洲综合| 88av免费观看| 亚洲六月丁香六月婷婷蜜芽| 麻豆国产人免费人成免费视频| 黄色免费在线网址| 亚洲精品免费观看| 午夜无遮挡羞羞漫画免费| 一个人免费观看日本www视频| 亚洲高清在线mv| 吃奶摸下高潮60分钟免费视频| 中文字幕看片在线a免费| 亚洲性无码av在线| 亚洲美女在线国产|