Compartilhar via


SPWebConfigModification Class

Holds modifications that are made to the web.config.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPWebConfigModification

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<GuidAttribute("2BE8CC87-138D-4A5F-96A7-A842D6364FA4")> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPWebConfigModification _
    Inherits SPAutoSerializingObject
'Usage
Dim instance As SPWebConfigModification
[GuidAttribute("2BE8CC87-138D-4A5F-96A7-A842D6364FA4")]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPWebConfigModification : SPAutoSerializingObject

Remarks

A collection of web.config modifications is a set of commands that, when processed by the web.config manipulator in Microsoft SharePoint Foundation, change the state of the web.config file. You can string together a set of these commands to ensure that they apply the desired tags and attributes within web.config. Each modification is expressed as an object in the administrative object model.

Use the WebConfigModifications property of the SPWebApplication or SPWebService class to get the collection of web.config modifications either in the Web application or in all Web applications within the Web service. To apply modifications that you define through the SPWebConfigModification class to the web.config files in the server farm, call the ApplyWebConfigModifications method on the current content Web service object, as follows: SPWebService.ContentService.ApplyWebConfigModifications

Examples

The following example adds a safe control entry to the safe controls section in web.config throughout the server farm.

Dim myService As SPWebService = SPWebService.ContentService
         
Dim myModification As New SPWebConfigModification()
myModification.Path = "configuration/SharePoint/SafeControls"
myModification.Name = "SafeControl[@Assembly='MyCustomAssembly'][@Namespace='MyCustomNamespace'][@TypeName='*'][@Safe='True']"
myModification.Sequence = 0
myModification.Owner = WebConfigModificationFeatureReceiver.OwnerId
myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode
myModification.Value = "<SafeControl Assembly='MyCustomAssembly' Namespace='MyCustomNamespace' TypeName='*' Safe='True' />"
         
myService.WebConfigModifications.Add(myModification)
myService.Update()
myService.ApplyWebConfigModifications()
SPWebService myService = SPWebService.ContentService;

SPWebConfigModification myModification = new SPWebConfigModification();
myModification.Path = "configuration/SharePoint/SafeControls";
myModification.Name = "SafeControl[@Assembly='MyCustomAssembly'][@Namespace='MyCustomNamespace'][@TypeName='*'][@Safe='True']";
myModification.Sequence = 0;
myModification.Owner = WebConfigModificationFeatureReceiver.OwnerId;
myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
myModification.Value = "<SafeControl Assembly='MyCustomAssembly' Namespace='MyCustomNamespace' TypeName='*' Safe='True' />";

myService.WebConfigModifications.Add(myModification);
myService.Update(); 
myService.ApplyWebConfigModifications();

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

SPWebConfigModification Members

Microsoft.SharePoint.Administration Namespace