开发者

Issue using custom HttpModule with ajax enabled (ScriptManager) asp.net webform (ASP.NET 4.0 / IIS 7 )

开发者 https://www.devze.com 2023-02-15 09:24 出处:网络
I\'ve a custom Httpmodule which handles PostAuthenticateRequest & PreRequestHandlerExecute events.

I've a custom Httpmodule which handles PostAuthenticateRequest & PreRequestHandlerExecute events.

However, when I try to use the module on page with ReportViwer (which needs ScriptManager) I get a bunch of browser errors such as following and the report viewer does not work as expected i.e. it doesn't show any result.

  1. ASP.NET Ajax clien开发者_JAVA技巧t-side framewook failed to load.
  2. 'Sys' is undefined
  3. Syntax error (WebResource.axd)
  4. 'Type' is undefined (ReportViewerWebControl.axd)

If I comment out the module from web.config everything works as expected (obviously without the module code). Can anyone help me understand and resolve this issue?

Thanks!!


I might have found a workaround to make my code work. However, I'm at loss to explain the default processing of ajax enabled web page.

I would like to thank Tony for his insight, which got me thinking in this direction.

To test the processing, I ran the module with the ajax enabled page which had an update panel which printed current system time. The update panel refreshed based on a timer control which went off every 10 seconds. What I observed was that for every request multiple calls were made to the httpmodule. The first call to the module has header that contained about 7 key-value pair such as Connection, Authorization, Host etc. The subsequent calls had some extra key-value pair among which couple of them caught my attention. They are x-requested-with and x-microsoftajax, which I believe XHttpRequest ... an ajax request.

So, in my workaround I just skipped processing of my module depending on presence of these header value somthing like the following.

 if (HttpContext.Current.Request.Headers["x-microsoftajax"] == null)
 { ... old code ... }

Once I do that, the module gets executed the during the first call and the execution is skipped every time its called as part of ajax processing.

0

精彩评论

暂无评论...
验证码 换一张
取 消