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

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

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

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

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

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

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論