ASP.NET中判断请求是否为Ajax请求一法

判断是否为ajaxRequest 在http请求头中查找是否包含X-Requested-With,并且值为XMLHttpRequest

string sheader = Request.header["X-Requested-With"];
bool isAjaxRequest = (sheade != null && sheader == "XMLHttpRequest") ? true : false;

 

 

判断是否微软ajax框架,只需判断头标题x-microsoftajax是否为Delta-true.

 

string sheader = Request.header["x-microsoftajax"];
bool isAjaxRequest = (sheade != null && sheader == "Delta-true") ? true : false;

 

你可能感兴趣的:(asp.net)