修正链接地址
修正链接地址
Code
#region //修改链接地址
public string UpdateTheUri(string webUri,string curUri)
{
if(curUri==string.Empty) return string.Empty;
curUri=curUri.Replace("\"","").Trim();
curUri=curUri.Replace("\'","").Trim();
curUri=curUri.Replace("target=_blank","").Trim();
curUri=curUri.Replace(" ","").Trim();
curUri=curUri.Replace("&","&").Trim();
if(!curUri.ToLower().StartsWith("http"))
{
if(curUri.IndexOf("../")!=-1)
{
int N=0;
int Num=-1;
Num=curUri.IndexOf("../",0);
while(Num!=-1)
{
N++;
curUri=curUri.Substring(Num+3);
Num=curUri.IndexOf("../",0);
}
for(int i=0;i<N;i++)
{
webUri = webUri.Substring(0, webUri.LastIndexOf("/"));
}
curUri = webUri + "/" + curUri;
}
else
{
curUri = curUri.Replace("./", "");
curUri = webUri.Substring(0, webUri.LastIndexOf("/") + 1) + curUri;
}
//去除地址中重复的 “//”
if(curUri.IndexOf("//")!=curUri.LastIndexOf("//"))
{
curUri=curUri.Replace("//","/");
curUri=curUri.Replace(":/","://");
}
}
if(Encoding.UTF8.GetByteCount(curUri)>390)//(curUri.Length>390)
{
curUri=string.Empty;
}
return curUri.Trim();
}
#endregion
#region //修改链接地址
public string UpdateTheUri(string webUri,string curUri)
{
if(curUri==string.Empty) return string.Empty;
curUri=curUri.Replace("\"","").Trim();
curUri=curUri.Replace("\'","").Trim();
curUri=curUri.Replace("target=_blank","").Trim();
curUri=curUri.Replace(" ","").Trim();
curUri=curUri.Replace("&","&").Trim();
if(!curUri.ToLower().StartsWith("http"))
{
if(curUri.IndexOf("../")!=-1)
{
int N=0;
int Num=-1;
Num=curUri.IndexOf("../",0);
while(Num!=-1)
{
N++;
curUri=curUri.Substring(Num+3);
Num=curUri.IndexOf("../",0);
}
for(int i=0;i<N;i++)
{
webUri = webUri.Substring(0, webUri.LastIndexOf("/"));
}
curUri = webUri + "/" + curUri;
}
else
{
curUri = curUri.Replace("./", "");
curUri = webUri.Substring(0, webUri.LastIndexOf("/") + 1) + curUri;
}
//去除地址中重复的 “//”
if(curUri.IndexOf("//")!=curUri.LastIndexOf("//"))
{
curUri=curUri.Replace("//","/");
curUri=curUri.Replace(":/","://");
}
}
if(Encoding.UTF8.GetByteCount(curUri)>390)//(curUri.Length>390)
{
curUri=string.Empty;
}
return curUri.Trim();
}
#endregion