AJAX breaking because of HttpModule, how to stop it from happening?
Need some help with a AJAX issue.
I have certain controls on a ASPX page which uses AJAX for async processing.
I also have a HttpModule for the specific site, which intercepts and Filters the HttpRequest.
Since Installing the Module, the AJAX controls are broken. These controls just seem to not return from their AJAX Post. Herewith the HttpModule Code:
public void Init(HttpApplication context)
{
context.ReleaseRequestState += new EventHandler(InstallResponseFilter);
}
public void Dispose()
{
}
private void InstallResponseFilter(object sender, EventArgs e)
{
HttpResponse response = HttpContext.Current.Response;
if (response.ContentType == "text/html")
开发者_运维知识库 {
response.Filter = new MyFilter(response.Filter);
}
}
Any Ideas? Thanks
Presumably your ajax responses are going out with content type "text/html"? Have you tried debugging to confirm if this is the case?
If so you could switch them to something else "application/json" or "text/xml" and see if that works. It depends what other uses your application makes of the content type property.
If you ajax responses aren't using this content type then it would appear this module wouldn't cause an issue. Again you should debug to confirm exactly what is happening.
You could also try adding further conditions to your InstallResponseFilter method, for example all ajax request from jquery have a certain header on them (x-requested-with) I think, possibly same is true for other frameworks. If you can identify a common signature of your ajax requests you an filter out the response filter.
精彩评论