Home »

How to identify AJAX request with C# in MVC.NET?

Question ListCategory: C#.NETHow to identify AJAX request with C# in MVC.NET?
jeanderson295 author asked 9 years ago
1 Answers
shah_kajal184 author answered 8 years ago

The solution is in depended from MVC.NET framework and universal across server-side technologies.
Most modern AJAX applications utilize XmlHTTPRequest to send async request to the server. Such
requests will have distinct request header:
X-Requested-With = XMLHTTPREQUEST

2849

MVC.NET provides helper function to check for Ajax requests which internally inspects X-Requested-
With request header to set IsAjax flag.
HelperPage.IsAjax Property
Gets a value that indicates whether Ajax is being used during the request of the Web page.
Namespace: System.Web.WebPages
Assembly: System.Web.WebPages.dll
However, same can be achieved by checking requests header directly:
Request[“X-Requested-With”] == “XmlHttpRequest”

Please login or Register to Submit Answer