我在用
HttpContext.Current.Request.IsAjaxRequest()
在 Application_Error 方法中检查 global.asax 中的 ajax 请求的条件,但我收到以下错误:
“System.Web.HttpRequest”不包含“IsAjaxRequest”的定义,并且最佳扩展方法重载“System.Web.Mvc.AjaxRequestExtensions.IsAjaxRequest(System.Web.HttpRequestBase)”有一些无效参数
下面是代码:
void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError().GetBaseException();
HttpException httpException = exception as HttpException;
string ErrorMessage = "";
ErrorMessage = "Application Level Error";
logger.Error(ErrorMessage, exception);
if (System.Web.HttpContext.Current.Request.IsAjaxRequest()) //if its an ajax do not redirect
{
return;
}
else
{
Server.ClearError();
this.Response.RedirectToRoute("Default", new { controller = "Home", action = "Error" });
}
}