SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to add a line in the web.config under authorizedtypes, I want to do it with a wsp solution so that sharepoint takes care of syncrhonizing it with other front end servers.

I just want to put this line:

<authorizedType Assembly="MyCompany.CustomActivities, Version=, Culture=neutral, PublicKeyToken=207090b9b3f674c8" Namespace="MyCompany.CustomActivities" TypeName="*" Authorized="True" />
share|improve this question
I found this site,, but my dll is already deployed in the gac and I already know the public key.\ – Esteban V Mar 23 '12 at 10:39
The important part of the msdn article isn't just building the right string. But more the use of SPWebConfigModification which will make the change to web.config on all servers (including future) – Per Jakobsen Mar 23 '12 at 10:59
up vote 5 down vote accepted

I've implemented this method in the past, so I just share my code with you:

private void AddAuthorizedType(SPWebApplication webApplication, string assembly, string namespace_)
         var modification = new SPWebConfigModification();
         modification.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes";
         modification.Name = string.Format("authorizedType[@Assembly='{0}'][@Namespace='{1}'][@TypeName='*'][@Authorized='True']", assembly, namespace_);
         modification.Sequence = 0;
         modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
         modification.Value = string.Format("<authorizedType Assembly='{0}' Namespace='{1}' TypeName='*' Authorized='True'/>", assembly, namespace_);

and remove:

private void RemoveAuthorizedType(SPWebApplication webApplication, string assembly, string namespace_)
        SPWebConfigModification configMod = null;
        var modsCollection = webApplication.WebConfigModifications;

        // Find the most recent modification of a specified owner
        foreach (SPWebConfigModification modification in modsCollection)
            if (modification.Name.Equals(string.Format("authorizedType[@Assembly='{0}'][@Namespace='{1}'][@TypeName='*'][@Authorized='True']", assembly, namespace_), StringComparison.OrdinalIgnoreCase))
                configMod = modification;

        if (configMod != null)
            // Remove it and save the change to the configuration database  

            // Reapply all the configuration modifications

NOTE: make sure this feature has web application scope, because if not, your code may not work, due to RemoteAdministratorAccessDenied settings.

share|improve this answer
That last bit about access and scope is very important :) – Rex M Mar 23 '12 at 12:32
@Kai, in my first link they say to make it farm scoped, :(, strange, I cant make it work!! see my other question here if you can help me.… – Esteban V Mar 23 '12 at 12:52
@superxman, you can make it farm scope, but you should to know what web application's config you are going to modify. If you make web application scope, you can simply use functions like this - AddAuthorizedType(feature.Parent as SPWebApplication, ...) – Kai Mar 23 '12 at 12:57

We've found it's much easier to just add a webconfig.something.xml file to the Config folder. So for your one entry you can create an xml file with these contents:

<?xml version="1.0" encoding="utf-8" ?>
  <remove path="configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes/authorizedType[@Namespace=&quot;MyCompany.CustomActivities&quot;]" />
  <add path="configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes" >
    <authorizedType Assembly="MyCompany.CustomActivities, Version=, Culture=neutral, PublicKeyToken=207090b9b3f674c8" Namespace="MyCompany.CustomActivities" TypeName="*" Authorized="True" />

Name this file in the form webconfig.something.xml replacing something with your Solution Name or something else to distinguish it.

This xml file can be part of your solution set to copy itself to [HivePath]\CONFIG folder. If you are creating your solution in Visual Studio just add a new Root File (SharePoint file-system template file). Add a CONFIG folder under the RootFiles folder and place your new xml file there.

Then whenever web.config rebuilds itself it will do so with your actions specified above. The first time you deploy the solution you will need to add an extra step of calling:

stsadm -o copyappbincontent

This is true for both SharePoint 2007 and SharePoint 2010.

share|improve this answer
interesting solution, and of course faster. thanks for sharing this. – Kai Mar 23 '12 at 13:22
Nice solution. If it's of interest, here is the MSDN documentation on this – Kirk Jul 24 '13 at 20:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.