Web.config implications of clearing sections? - asp.net

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=31BF3856AD364E35"/>
<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.

Related

asp.net webforms modules and handlers section - is remove required?

Below is the default configuration for ASP.NET webforms web.config for specifying handlers and modules under IIS 7 (.5)
When you add custom modules and handlers, I would like to know if remove name ="custom module" is required before adding the module entry. I couldn't find much information on this on whether or why remove is required. I saw some examples where they didn't have removes.
The reason why I'm asking is I vaguely remember reading something about module references will keep adding same entries every time instead of having just one, eventually failing. But I can't find that anywhere now.
If someone can confirm, it will be much appreciated.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</handlers>
</system.webServer>
Taking a look in the MSDN, but in the <add> page, you will read this:
The <add> directives are processed in top-down, sequential order. If
two or more <add> subdirectives specify the same verb/path
combination, the final overrides all others.
Based on that, in order for a <add> directive to be overridden, it must have the same verb/path combination. If they do not match, both directives are active and that might cause conflict issues.
Removing the existing directives before declaring your own is a good practice to avoid any conflicts.
Edit: Your application inherits settings from other web.config files as well (See here for more info). Those can be the machine.config, the root web.config etc. Those files can contain module and handler declarations as well. Adding <remove> helps you avoid any conflicts with those files.

Url Routing working on localhost but Not on server

I uses asp.net 3.5 for buiding my application,
I use URL routing in it and it works fine in my local host
In my web.config file i do the following setting
<system.web>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="RoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule,
System.Web.Routing, Version=3.5.0.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
<remove name="UrlRoutingHandler"/>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*" path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler,
System.Web, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
But when i deploy the application on my server which has IIS 7 and windows 2008 r2 then routing doesn't work there.I think i have to do some iis setting or to change some web.config code....
so please anyone suggest me some answer
Have you thought about implementing Page Routing from you web-app?
One problem that you might incur, is if your using AJAX (Toolkit or Extensions) you will need to implement:
'Ignores any Resource cache references, used heavily in AJAX interactions.
rts.Ignore("{resource}.axd/{*pathInfo}")
To keep from getting Sys is undefined errors while debugging.

The element > system.webServer' has invalid child > element 'rewrite'

Warning 1 The element
'system.webServer' has invalid child
element 'rewrite'. List of possible
elements expected: 'asp, caching, cgi,
defaultDocument, directoryBrowse,
globalModules, handlers,
httpCompression, httpErrors,
httpLogging, httpProtocol,
httpRedirect, httpTracing,
isapiFilters, modules, odbcLogging,
security, serverRuntime,
serverSideInclude, staticContent,
tracing, urlCompression, validation,
management'. D:\PROJEKTI\FoodOrder\FoodOrder\Web.config 185 4 FoodOrder
code:
system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</handlers>
<rewrite>
<rewriteMaps>
<rewriteMap name="StaticRewrites">
<!--<add key="/Default.aspx" value="/Default.aspx" />-->
</rewriteMap>
</rewriteMaps>
<rules>
page works but i always get warning of this and when i publish page i get publish error becouse of this...
Possible duplicate of asp.net, url rewrite module and web.config
This happens when Visual Studio IntelliSense doesn't find information about rewrite module on schema file. Hence we need to add schema for rewrite section in a file specifically: DotNetConfig.xsd
Ruslan provides unofficial schema for rewrite. For Visual Studio 2010, please download xml schema from his page: http://ruslany.net/2010/04/visual-studio-xml-intellisense-for-url-rewrite-2-0/
For earlier versions download from here:
http://ruslany.net/2009/08/visual-studio-xml-intellisense-for-url-rewrite-1-1/#comment-1402
For both versions, instructions are here.
For VS2010 remember to replace %VS90COMNTOOLS% with %VS100COMNTOOLS%
For VS2012 and later, follow fftsys's article.
If you do not want to use ruslany's script you can still use rewrite module. In that case, you still can modify web.config to add rewrite section out of visual studio.
Original rewrite module for IIS comes from Microsoft: http://www.iis.net/downloads/microsoft/url-rewrite and supported by them. ruslany's script just enables support in Visual Studio so that VS recognizes it.

Intellegencia urlrewriter is not working showing 404 page not found

These are some extracts from my web.config file on development server. Intelligencia URL was fine but when deployed on production(IIS 5 on both servers) it returns page not found(404 error) on every rewritten url except for one which has ~/(guid value).aspx/value (rewriiten url) working
<section name="rewriter" requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,
Intelligencia.UrlRewriter"/>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule"/>
</modules>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
</modules>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode"/>
</handlers>
</system.webServer>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter"
name="UrlRewriter"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
<rewriter>
<rewrite url="~/myone/tags/(.+)" to="~/myone/tagpage.aspx?tag=$1"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
</httpHandlers>
We have a similar rule that uses (.*) instead of (.+). Might work for you (if that's acceptable for your use cases).
Go Run -> inetmgr -> select your website -> right click on properties and select Configuration.
Select C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll in executables and in extension place.
Uncheck "VERIFY THAT FILE EXISTS."

ASP.NET Ajax not running with IIS 7

I have a small web application with ASP.NET AJAX running well under the Cassini ASP.NET from http://www.ultidev.com/. But when I tried to host it under IIS7, the AJAX is not working. The UpdatePanel, the Calendar extension, the client side validation from the Validation Control are not working at all. I think it must be a problem of IIS 7.
Here's a section of the web.config file:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/></handlers>
</system.webServer>
Can anyone tell me what the problme is with IIS 7? How should I configure it to work with ASP.NET AJAX? Thank you.
Add the following line in the Handlers section in the web.config file:
<add name="Ajax" verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
I just removed Web Server role and added Web Server role again. It's working now. I think maybe some component that IIS 7 was set up in the first place.
Delete the next code line if you added AJAX from NUGET and after you add ajaxcontroltoolkit.dll from
here: http://ajaxcontroltoolkit.codeplex.com/releases/view/109918
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/>
PD: AJAX CONTROL TOOL KIT 4.5 NOT WORKS WITH FRAMEWORK 4.5. AND AJAX FROM NUGET HAS PROBLEM

Resources