根据给出的相对地址获取网站绝对地址
2017-03-15 09:15
337 查看
如标题给出示例,例如:给出 /login.aspx 可以返回http://www.onewill.com,cn/login.aspx 的绝对地址结果。
/// 根据给出的相对地址获取网站绝对地址
/// </summary>
/// <param name="localPath">相对地址</param>
/// <returns>绝对地址</returns>
public 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;
}
/// 根据给出的相对地址获取网站绝对地址
/// </summary>
/// <param name="localPath">相对地址</param>
/// <returns>绝对地址</returns>
public 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;
}
相关文章推荐
- asp.net项目中根据给出的相对地址获取网站绝对地址的C#代码
- C#实现根据给出的相对地址获取网站绝对地址的方法
- asp.net根据相对路径获取绝对路径
- Java项目中根据相对路径和绝对路径获取文件的方法 getResource(name)
- 根据Email域名获取Email网站地址
- C++ 根据当前路径与相对路径,获取绝对路径
- 获取网站根目录地址(绝对路径地址)
- java URL根据相对路径获取绝对路径
- 根据一个绝对路径获取相对路径的方法
- Web API中如何获取相对地址的绝对地址 Server.MapPath
- win8,win8.1应用中怎样获取前台图片的相对地址或绝对地址和怎样在书写代码时的需要给多个标签进行粘贴同一个属性的捷径
- jsp获取某网站所有链接地址
- 判断是否为链接地址的正则表达式(包括相对和绝对地址)
- 根据Url地址得到网页的html源码,截取网站信息的核心程序
- javascript 根据歌名获取播放地址和歌词内容
- dedecms图片相对地址和绝对地址的问题
- 从页面中取出e-mail地址和相对链接及绝对链接的代码...
- 根据PE文件格式获取LoadLibraryA()/GetProcAddress()地址
- servlet/jsp 获取绝对路径和相对路径
- 什么是绝对地址和相对地址?