AnsweredAssumed Answered

Question on making modifications to web.config

Question asked by stacie.weffelmeyer@wwt.com on Feb 5, 2015
Latest reply on Feb 25, 2015 by stacie.weffelmeyer@wwt.com

Asking on behalf of one of our developers.

 

Hello,

 

I am a developer on the sharepoint 2010 team at World Wide
Technology.  We have your Workflow and Forms products.

 

We created a web application feature that adds the below
code to the web.config using Microsoft's supported SPWebConfigModification
class from Microsoft.Sharepoint.Administration namespace. It only does this on
feature activation/deactivation:

 

public override void
FeatureActivated(SPFeatureReceiverProperties properties)

{

SPWebApplication webApp = properties.Feature.Parent as
SPWebApplication;

  1. webApp.WebConfigModifications.Clear();

 

SPWebConfigModification myModification = new
SPWebConfigModification();

  1. myModification.Path = "configuration/system.web";
  2. myModification.Name = "webServices";
  3. myModification.Sequence = 0;
  4. myModification.Owner = "WWTWebServices";
  5. myModification.Type =
    SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
  6. myModification.Value =
    "<webServices></webServices>";

 

SPWebConfigModification myModification2 = new
SPWebConfigModification();

myModification2.Path =
"configuration/system.web/webServices";

myModification2.Name = "protocols";

myModification2.Sequence = 1;

myModification2.Owner = "WWTWebServices";

myModification2.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

myModification2.Value =
"<protocols></protocols>";

 

SPWebConfigModification myModification3 = new
SPWebConfigModification();

myModification3.Path =
"configuration/system.web/webServices/protocols";

myModification3.Name = "add [@name='HttpGet']";

myModification3.Sequence = 2;

myModification3.Owner = "WWTWebServices";

myModification3.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

myModification3.Value = "<add name='HttpGet'/>";

 

SPWebConfigModification myModification4 = new
SPWebConfigModification();

myModification4.Path =
"configuration/system.web/webServices/protocols";

myModification4.Name = "add [@name='HttpPost']";

myModification4.Sequence = 3;

myModification4.Owner = "WWTWebServices";

myModification4.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

myModification4.Value = "<add
name='HttpPost'/>";

 

  1. webApp.WebConfigModifications.Add(myModification);
  2. webApp.WebConfigModifications.Add(myModification2);
  3. webApp.WebConfigModifications.Add(myModification3);
  4. webApp.WebConfigModifications.Add(myModification4);

 

/*Call Update and ApplyWebConfigModifications to save
changes*/

  1. webApp.Update();
  2. webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

}

 

// Uncomment the method below to handle the event raised
before a feature is deactivated.

 

public override void
FeatureDeactivating(SPFeatureReceiverProperties properties)

{

SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

 

SPWebConfigModification myModification = new
SPWebConfigModification();

  1. myModification.Path = "configuration/system.web";
  2. myModification.Name = "webServices";
  3. myModification.Sequence = 0;
  4. myModification.Owner = "WWTWebServices";
  5. myModification.Type =
    SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
  6. myModification.Value =
    "<webServices></webServices>";

 

SPWebConfigModification myModification2 = new
SPWebConfigModification();

myModification2.Path = "configuration/system.web/webServices";

myModification2.Name = "protocols";

myModification2.Sequence = 1;

myModification2.Owner = "WWTWebServices";

myModification2.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

myModification2.Value = "<protocols></protocols>";

 

SPWebConfigModification myModification3 = new
SPWebConfigModification();

myModification3.Path =
"configuration/system.web/webServices/protocols";

myModification3.Name = "add [@name='HttpGet']";

myModification3.Sequence = 2;

myModification3.Owner = "WWTWebServices";

myModification3.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

myModification3.Value = "<add
name='HttpGet'/>";

 

SPWebConfigModification myModification4 = new
SPWebConfigModification();

myModification4.Path =
"configuration/system.web/webServices/protocols";

myModification4.Name = "add [@name='HttpPost']";

myModification4.Sequence = 3;

myModification4.Owner = "WWTWebServices";

myModification4.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

myModification4.Value = "<add
name='HttpPost'/>";

 

  1. webApp.WebConfigModifications.Remove(myModification);
  2. webApp.WebConfigModifications.Remove(myModification2);
  3. webApp.WebConfigModifications.Remove(myModification3);
  4. webApp.WebConfigModifications.Remove(myModification4);

 

/*Call Update and ApplyWebConfigModifications to save
changes*/

  1. webApp.Update();
  2. webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

}

 

We needed to do this for a custom .asmx web service of our
own that we made.  However, turning this feature on/off is causing errors
with Nintex web services. Why is this, and how we might avoid. We are editing
the web.config per Microsoft's recommendations (as far as we can tell from the
TechNet documentation).

 

Thanks.

Outcomes