Is there a way to put an error handler HTTPModule at the beginning of the modules section in web.config without doing this manually?
I've tried the supplemental web.config approach like this:
<add path="configuration/system.webServer/modules" id="{125A654F-9220-42F0-A97A-1746252468DE}">
<add name="CustomErrorHandler" type="com.handlers.CustomErrorHandler, Assemblyname, Version=4.5.6.7, Culture=neutral, PublicKeyToken=3450345789" />
</add>
The problem is that the custom error handler has to be placed before the standard handler. If you don't, sharepoint handles the exception itself and delivers the standard exception page.
Expected:
<modules runAllManagedModulesForAllRequests="true">
<add name="CustomErrorHandler" type="com.handlers.CustomErrorHandler, Assemblyname, Version=4.5.6.7, Culture=neutral, PublicKeyToken=3450345789" />
<remove name="FileAuthorization" />
<remove name="Profile" />
<remove name="WebDAVModule" />
<remove name="Session" />
<add name="SPRequestModule" preCondition="integratedMode" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="SharePoint14Module" preCondition="integratedMode" />
<add name="StateServiceModule" type="Microsoft.Office.Server.Administration.StateModule, Microsoft.Office.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="RSRedirectModule" type="Microsoft.ReportingServices.SharePoint.Soap.RSRedirectModule, RSSharePointSoapProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
<add name="PublishingHttpModule" type="Microsoft.SharePoint.Publishing.PublishingHttpModule, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
</modules>
Result by supplemental approach:
<modules runAllManagedModulesForAllRequests="true">
<remove name="FileAuthorization" />
<remove name="Profile" />
<remove name="WebDAVModule" />
<remove name="Session" />
<add name="SPRequestModule" preCondition="integratedMode" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="SharePoint14Module" preCondition="integratedMode" />
<add name="StateServiceModule" type="Microsoft.Office.Server.Administration.StateModule, Microsoft.Office.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="RSRedirectModule" type="Microsoft.ReportingServices.SharePoint.Soap.RSRedirectModule, RSSharePointSoapProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
<add name="PublishingHttpModule" type="Microsoft.SharePoint.Publishing.PublishingHttpModule, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="CustomErrorHandler" type="com.handlers.CustomErrorHandler, Assemblyname, Version=4.5.6.7, Culture=neutral, PublicKeyToken=3450345789" />
</modules>
Like this thread says (confiremd by MS Developer) there is no way to control the order of nodes when working with SPWebConfigModification:
Adding the web.config entry manually is no option.
Is there really no other way?