public static bool CheckUrl()
{
Uri ComeUrl = HttpContext.Current.Request.UrlReferrer;
string cUrl;
if (ComeUrl == null)
{ return false; }
else
{
string reffer = ComeUrl.ToString();
cUrl = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
if (reffer.Substring(cUrl.Length, 1) == ":")
{
cUrl += ":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString();
}
int lenth;
lenth = cUrl.Length;
cUrl += HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"];
int result;
result = String.Compare(reffer, 1, cUrl, 1, lenth, true);
return (result == 0);
}
}
本文介绍了一个用于检查HTTP请求中URL来源是否合法的方法。该方法通过对比请求的referrer与当前服务器的URL来判断请求的有效性。

2892

被折叠的 条评论
为什么被折叠?



