C#實現根據給出的相對位址擷取網站絕對位址的方法

來源:互聯網
上載者:User

標籤:content   pos   串連   margin   cal   pad   color   不同   網站   

本文執行個體講述了C#實現根據給出的相對位址擷取網站絕對位址的方法。分享給大家供大家參考。具體分析如下:

這段C#代碼在ASP.NET的項目中可以根據給定的相對位址擷取絕對訪問地址,例如:給出 /codes/index.php 可以返回http://www.jb51.net/codes/index.php的絕對位址結果。

/// <summary>/// 根據給出的相對位址擷取網站絕對位址/// </summary>/// <param name="localPath">相對位址</param>/// <returns>絕對位址</returns>public static string GetWebPath(string localPath){  string path = HttpContext.Current.Request.ApplicationPath;  string thisPath;  string thisLocalPath;  //如果不是根目錄就加上"/" 根目錄自己會加"/"  if (path != "/")  { thisPath = path + "/";  }  else  { thisPath = path;  }  if (localPath.StartsWith("~/"))  { thisLocalPath = localPath.Substring(2);  }  else  { return localPath;  }  return thisPath + thisLocalPath;}

希望本文所述對大家的C#程式設計有所協助。

除聲明外, 跑步客文章均為原創,轉載請以連結形式標明本文地址
  C#實現根據給出的相對位址擷取網站絕對位址的方法

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23060.html






相關內容C# 中的var關鍵字詳細介紹C#操作SQLite資料庫方法小結(建立,串連,插入,查詢,刪除等)C#使用Mutex簡單實現程式單一實例啟動並執行方法C#在RichTextBox中顯示不同顏色文字的方法
C#實現控制Windows系統關機、重啟和登出的方法C#實現洗牌演算法C#中多態、重載、重寫區別分析C#利用Windows內建gdi32.dll實現抓取螢幕功能執行個體

C#實現根據給出的相對位址擷取網站絕對位址的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.