HttpModules设置被忽略?

时间:2014-11-04 17:15:18

标签: asp.net webforms web-config httpmodule

我正在升级旧的WebForms应用程序。但是,它没有拿起自定义主题。

我的web.config文件包含以下内容:

<system.web>
  <httpModules>
    <add name="ThemeManager" type="SoftCircuits.MediCorp.ThemeManager"/>
  </httpModules>
</system.web>

以下是该课程定义的一部分:

public class ThemeManager : IHttpModule
{
    const string _defaultTheme = "BlueSky";

    public ThemeManager()
    {
    }

    public void Init(HttpApplication app)
    {
        app.PreRequestHandlerExecute += new EventHandler(Context_PreRequestHandlerExecute);
    }

    void Context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        if (HttpContext.Current.CurrentHandler is Page && HttpContext.Current.Session != null)
        {
            Page page = (Page)HttpContext.Current.CurrentHandler;

            // Note: To override the theme set here, set Theme = null in page's PreInit event
            if (page != null && !HttpContext.Current.Request.FilePath.Contains("Help/"))
            {
            ...

但似乎该类从未实例化。我可以在构造函数,Init()处理程序或PreRequestHandlerExecute()处理程序中设置断点,并且不会触发任何断点。

这一次都有效。任何人都可以看到缺少的东西吗?

注意:我不知道它是否有任何区别,但我也在web.config文件中指定了<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />

1 个答案:

答案 0 :(得分:0)

原来,对于IIS 7.0集成模式,无论集成模式是什么,web.config语法都已更改。

而不是我的问题中的配置,它需要按如下方式完成。

<system.webServer>
  <modules>
    <add name="ThemeManager" type="SoftCircuits.MediCorp.ThemeManager"/>
  </modules>
</system.webServer>

为我修好了。

http://msdn.microsoft.com/en-us/library/vstudio/ms227673(v=vs.100).aspx

相关问题