/// <summary> /// 根据相对路径得到绝对路径 /// </summary> /// <param name="sUrl">输入内容</param> /// <param name="sInput">原始网站地址</param> /// <param name="sRelativeUrl">相对链接地址</param> public static string GetUrl(string sInput, string sRelativeUrl) { string sReturnUrl = ""; string sUrl = _GetStandardUrlDepth(sInput);//返回了http://www.163.com/news/这种形式 if (sRelativeUrl.ToLower().StartsWith("http") || sRelativeUrl.ToLower().StartsWith("https")) { sReturnUrl = sRelativeUrl.Trim(); } else if (sRelativeUrl.StartsWith("/")) { sReturnUrl = GetDomain(sInput) + sRelativeUrl; } else if (sRelativeUrl.StartsWith("../")) { sUrl = sUrl.Substring(0, sUrl.Length - 1); while (sRelativeUrl.IndexOf("../") >= 0) { string temp = CString.GetPreStrByLast(sUrl, "/"); if (temp.Length > 6) {//temp != "http:/",否则的话,说明已经回溯到尽头了,"../"与网址的层次对应不上。存在这种情况,网页上面的链接是错误的,但浏览器还能正常显示 sUrl = temp; } sRelativeUrl = sRelativeUrl.Substring(3); } sReturnUrl = sUrl + "/" + sRelativeUrl.Trim(); } else if (sRelativeUrl.StartsWith("./")) { sReturnUrl = sUrl + sRelativeUrl.Trim().Substring(2); } else if (sRelativeUrl.Trim() != "") {//2007images/modecss.css sReturnUrl = sUrl + sRelativeUrl.Trim(); } else { sRelativeUrl = sUrl; } return(sReturnUrl); }
public static string GetUrl(string sInput, string sRelativeUrl) { string sOrg = smethod_0(sInput); if (sRelativeUrl.ToLower().StartsWith("http") || sRelativeUrl.ToLower().StartsWith("https")) { return(sRelativeUrl.Trim()); } if (sRelativeUrl.StartsWith("/")) { return(GetDomain(sInput) + sRelativeUrl); } if (sRelativeUrl.StartsWith("../")) { sOrg = sOrg.Substring(0, sOrg.Length - 1); while (sRelativeUrl.IndexOf("../") >= 0) { string preStrByLast = CString.GetPreStrByLast(sOrg, "/"); if (preStrByLast.Length > 6) { sOrg = preStrByLast; } sRelativeUrl = sRelativeUrl.Substring(3); } return(sOrg + "/" + sRelativeUrl.Trim()); } if (sRelativeUrl.StartsWith("./")) { return(sOrg + sRelativeUrl.Trim().Substring(2)); } if (sRelativeUrl.Trim() != "") { return(sOrg + sRelativeUrl.Trim()); } sRelativeUrl = sOrg; return(""); }