开发者

Web.config implications of clearing sections?

I've come across code like this:

    <modules>
        <remove name="ScriptModule"/>
        <remove name="YafTaskModule"/>
        <remove name="UrlRewriter"/>

        <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF385开发者_StackOverflow社区6AD364E35"/>
        <add name="YafTaskModule" type="YAF.Core.YafTaskModule, YAF.Core" preCondition="managedHandler"/>
        <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" preCondition="managedHandler"/>
    </modules>

And it sometimes breaks, for example if your parent AppDomain doesn't have an UrlRewriter module in it, an error is raised.

How unsafe is it to use:

    <modules>
        <clear/>

        <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="YafTaskModule" type="YAF.Core.YafTaskModule, YAF.Core" preCondition="managedHandler"/>
        <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" preCondition="managedHandler"/>
    </modules>

Same happens in <httpModules> and a few other tags


The main issue with <clear /> is that it will clear all configured elements from all ancestor config files such as parent folder, machine level web.config and machine.config. So in case of <httpModules>, clearing will take out all essential ASP.NET modules such as authentication, session state management, output caching etc. In case your application depends on some of these modules then it will not work.

So the solution is that you must add those modules specifically after clearing the section which is actually correct solution for your problem. Downside is that your config file may become a bit verbose.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜