Domanda

I have a 3rd party control that i want to add to the web part. That 3rd party control uses a generic ASHX handler. I can always add the registration to the actual WFE web.config but it's a bit manual to my tastes. Does anyone succeeded to add to web.config using a deployment package?
i would need something like this:

<system.webServer>
   <handlers>
      <remove name="SomeHandler" />
      <add name="SomeHandler" preCondition="IntegratedMode" 
           verb="GET" path="SomeHandler.ashx" type="SomeHandler, SomeHandler" />
   </handler>
</system.webServer>

Update
Here is the code that I ended up creating in the feature receiver:

var modifications = new List<SPWebConfigModification>()
                    {
                            new SPWebConfigModification("remove[@name='BotDetectCaptachHandler'",
                                                        "configuration/system.webServer/handlers")
                            {
                                Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
                                Value = @"<remove name='BotDetectCaptchaHandler'/>"
                            },
                            new SPWebConfigModification("add[@name='BotDetectCaptchaHandler'",
                                                        "configuration/system.webServer/handlers")
                            {
                                Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
                                Value = @"<add name='BotDetectCaptchaHandler' preCondition='integratedMode' verb='GET' path='BotDetectCaptcha.ashx' type='BotDetect.Web.CaptchaHandler, BotDetect' />"
                            }
                    };

SPSecurity.RunWithElevatedPrivileges( () =>
                         {
                               var contentService = SPWebService.ContentService;
                               foreach (var modification in modifications)
                               {
                                   contentService.WebConfigModifications.Add(modification);
                                }
                                contentService.Update();
                                contentService.ApplyWebConfigModifications();
                          });

When I do activate i get an error message saying that i have previously queue modifications failing to execute. Does anyone know how to query queued modifications and remove them? I tried PowerShell but was not successful. It seems that SPWebApplication.WebConfigModifications collection is always empty.

È stato utile?

Soluzione

I would use a SPWebConfigModification: http://msdn.microsoft.com/en-us/library/bb861909.aspx

Something similar to this:

SPWebConfigModification handlerMod = new SPWebConfigModification();
handlerMod.Path = "configuration/system.webServer/handlers";
handlerMod.Name = "add[@name='SomeHandler'][@type='SomeHandler']";
handlerMod.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
handlerMod.Value = "<add name=\"SomeHandler\" preCondition=\"IntegratedMode\" verb=\"GET\" path=\"SomeHandler.ashx\" type=\"SomeHandler, SomeHandler\" />";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top