Introduction
While working in SharePoint, I know the difficulties a developer face due to security issues. Here is a simple example how to modify your SharePoint web config file programmatically.
Background
If you are using some external DLL ( third party DLLs) then you may need to modify the "trust level" from wss_minimal to full. In that case you may want to do it programmatically insted of doing this manually.
Here is the code spinet for achieving this task.
Using the code
First of all I am doing all these things in feature activate of the feature.
Just put the following code in your feature activation block.
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
SPWebConfigModification myModification = newSPWebConfigModification("level", "configuration/system.web/trust");
System.Collections.ObjectModel.Collection<SPWebConfigModification> allModifications = webApp.WebConfigModifications;
myModification.Value = "Full";
myModification.Owner = "TapanKumar";
myModification.Sequence = 1;
myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
allModifications.Add(myModification);
SPFarm.Local.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
webApp.Update();
Remember this will work for the whole SPFarm. If you want it for a single site only then use SPSite insted of SPFarm