0
votes

We have a farm with 2 servers. I have applied some changes to the web.config on both servers. (I have a specific web application i.e. I have applied the changes in the web.config of my sharepoint web application and NOT the default Sharepoint site or the central admin site) But it seems that Sharepoint does not take into consideration these changes! For example I added an assembly reference .... but sharepoint was still throwing an assembly reference exception. i had to add the assembly reference to each and every control. I have also increased the execution timeout but it still gives timeouts.

This happens in the production environment only.

In the test (where there is a single server) I update the web.config and all changes work.

Is it because I should not be updating the web config. I have noticed there is an SPWebConfigModification class. Do I have to use this ? won't it do the same changes as I would have done manually.

Update .... I have now used the SPWebConfigModification and also did an iisreset ... but the changes were simply ignored!

Update 2...

Some more details on my web.config updates

I had added an assembly reference under assemmblies sectuion, somethign like this: This did not work as Sharepoint was still throwing an exception that the assembly cannot be found. This problem only happens in the production environment. In dev and test, I was also receiving the exception but when I added the assembly reference above, the error disappeared.

Another thing which did not work is the executionTimeout. I have added this to the production environment but sharepoint is still giving timeouts an a long request wich we have. Again, this entry solved the problem in the test and development environments.

2
You do not have to use SPWebConfigModifications whereas you should use it. You say that SharePoint doesn't consider your changes. When you make changes in the web.config try to make an iisreset (this usually is done automatically). What changes exactly are you making? Try making some other weird changes and see if they are considered. Try each server on its own without Load Balancer. Do both servers have teh same problem?Dennis G
Yes I did an iisreset but it did not have any effect.Joseph Caruana
Thanks for your reply. I have added more details on the web.config changes which I added (refer to update 2 please). Unfortunately, it is a bit difficult to do the tests you are mentioning as problem is happening only on the production environment.Joseph Caruana

2 Answers

1
votes

I wrote this for this for Sharepoint 2007, I think you need to modify the impersonation (RunWithElevatedPrivileges) but the rest should work:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

  SPSecurity.RunWithElevatedPrivileges(delegate() {

  try
  {

     Trace.WriteLine("Try to modify web.config");
     SPWebApplication myWebApp = ((SPWeb)properties.Feature.Parent).Site.WebApplication;

     WebConfigModifier mod = new WebConfigModifier(myWebApp, OwnerString);

     mod.AddModification(
        "SafeControl[@Assembly='Elsni.WorldsBestProgram, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e7639c2c71f2f003']",
        "configuration/SharePoint/SafeControls",
        "<SafeControl Assembly='Elsni.WorldsBestProgram, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e7639c2c71f2f003' Namespace='GFA.UniversalListSyncSolution' TypeName='*' Safe='True' />"
     );

     mod.AddModification(
        "add[@key='PropertiesSiteUrl']",
        "configuration/appSettings",
        "<add key=\"PropertiesSiteUrl\" value=\"http://iei-developersy/sites/gfaadmin/\" />"
     );

     mod.Update();
     Trace.WriteLine("Done.");
  }
  catch (Exception ex)
  {
     Trace.WriteLine("ERROR while activating feature: " + ex.Message);
  }
}
});
}
1
votes

As you have pointed out, you need to make these changes using the SPWebConfigModification class. It is possible to make the changes manually, however, this usually results in random issues caused by replication issues etc ....

The SPWebConfigModification class will ensure the change is stored in the SP database and amend the web.config files on your behalf.