ASP.Net Custom HttpModule
I am trying to create a custom HttpModule
for a web application. In the module I am writing session variables. This works except on pages with an Ajax ScriptManager
. When the page loads I get the dreaded 'Sys' is undefined
. This only happens on pages 开发者_开发知识库with ScriptManager
. To debug the problem I removed my HttpModule
from the application and moved the code to the global.asax in the application. Now this is the only event method I have in my global.asax:
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
application.Session["aVariable"] = "some value";
}
Any page/master page that has a ScriptManager
throws one or more "'Sys' is undefined"
errors.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
The app is in .NET 3.5.
Please help.
I have had a problem with this before. There are a lot of causes but this one fixed it for me...
Here is an extract from the post I wrote about it.
Finally after double checking absolutely everything I noticed that one of the handlers the web config was referencing did not have an extension mapping. This was the .axd extension. I added this in to IIS but the problem still occurred. Checking the handler mapping again I unchecked the 'Verify that the file exists' check box and retried the web page. This time it worked!
full post with screenshot @ http://wraithnath.blogspot.com/2010/09/ajax-sys-in-undefined-and-ajax-client.html
hope it helps
Thanks but the verify option is already checked.
I did notice that the only time I get this error is when I try to write a session variable in the "PreRequestHandlerExecute" event and the following tag is on the page:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
Found the solution.
Just had to add "if (System.Web.HttpContext.Current.Session != null)"
.
Thanks.
精彩评论