欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)根據(jù)給出的相對地址獲取網(wǎng)站絕對地址的方法

 更新時間:2015年03月26日 15:57:06   作者:feige  
這篇文章主要介紹了C#實現(xiàn)根據(jù)給出的相對地址獲取網(wǎng)站絕對地址的方法,涉及C#URL及字符串操作的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了C#實現(xiàn)根據(jù)給出的相對地址獲取網(wǎng)站絕對地址的方法。分享給大家供大家參考。具體分析如下:

這段C#代碼在ASP.NET的項目中可以根據(jù)給定的相對地址獲取絕對訪問地址,例如:給出 /codes/index.php 可以返回http://www.dbjr.com.cn/codes/index.php的絕對地址結果。

/// <summary>
/// 根據(jù)給出的相對地址獲取網(wǎng)站絕對地址
/// </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#程序設計有所幫助。

相關文章

最新評論