.Net下有一种处理路径的方法,如:path.Combine(path1,path2),这样来合并路径是不是也有一种这样的办法来处理url??
比如:以页面 http://www.microsoft.com/abc/123.aspx 为根页面
我希望将把相对网址 ../bcd/789.aspx 与上述网址合并结果网址效果:
http://www.microsoft.com/bcd/789.aspx
比如:以页面 http://www.microsoft.com/abc/123.aspx 为根页面
我希望将把相对网址 ../bcd/789.aspx 与上述网址合并结果网址效果:
http://www.microsoft.com/bcd/789.aspx
public static string Combine(System.Web.UI.Page page,string exPath)
{
string fixUrl="";
string oldUrl="";
string absolutePath="";
oldUrl=page.Request.Url.ToString();
absolutePath=page.Request.Url.AbsolutePath.ToString();
if (exPath.Substring(0,1) !="/")
{
exPath=string.Concat("/",exPath);
}
fixUrl=string.Concat(oldUrl.Remove(absolutePath),exPath);
return fixUrl;
}
两个参数,page为当前页,exPath为要粘贴的页
调用Combine(this.page,"/aaaa/asdss.aspx")
临时编写,没有测试,错了莫怪!
放到你的公用类里不是和调用系统函数一样吗?简单的一句Combine(this.page,"/aaaa/asdss.aspx")麻烦不到哪去吧?莫非你的作品里都不带自定义类?
**********************************
你这个类,如果后面的url象这样../../..//abc/cda/abc.aspx处理就不好
System.Web.VirtualPathUtility.Combine
****************************
VirtualPathUtility.Combine只支持虚拟目录路径操作