#region 判断是否服务器端提交
/// <summary>
/// 判断是否服务器端提交
/// </summary>
/// <returns></returns>
public static bool Judge_ThisSubmit()
{
string text1 = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"];
string text2 = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
string text3 = string.Empty;
if (text1 != null)
{
text3 = text1.Substring(7, text2.Length);//根据网站地址确定
}
if (text3 != text2)
{
return false;
}
return true;
}
#endregion
后台有时做权限时为了更安全 往往防止外部提交和直接输入地址访问 以下的函数可进行判断:
public bool CheckUrl()
{
Uri ComeUrl = Request.UrlReferrer;//取得来访URl源
string cUrl;
if (ComeUrl==null)
{
return false;
}
else
{
string reffer= ComeUrl.ToString(); ;
cUrl = "http://" + Request.ServerVariables["SERVER_NAME"];
if (reffer.Substring(cUrl.Length, 1) == ":")
{
cUrl += ":" + Request.ServerVariables["SERVER_PORT"].ToString();
}
int lenth;
lenth = cUrl.Length;
cUrl += Request.ServerVariables["SCRIPT_NAME"];
int result;
result = String.Compare(reffer, 1, cUrl, 1, lenth, true);
return (result==0);
}
}