문제

in Global.asax.cs, I'm trying to filter out all the XHR requests in order to log them.

However, both the HttpContext.Current.Request and the HttpContext.Current.Response don't seem to provide this information.

Is there some property field I missed? Or is there another way of knowing if a request is XHR?

도움이 되었습니까?

해결책

If you're using MVC you can use the IsAjaxRequest() extension method.

Request.IsAjaxRequest();

It's defined in System.Web.Mvc so if you don't already have a using statement for that namespace you'll need to add one.

다른 팁

try this.

protected void Application_EndRequest()
        {
            if (Context.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
            {
            }
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top