I'm developing a little installer for some SharePoint features that contain some web parts and a custom Web Service that's used to communicate with a 3rd party application that reads information from some electronic components.

Everything is working fine, but to make it work, i had to enable Anonymous Authentication on my SharePoint's server IIS. I can easily programmatically achieve this on my windows forms installer using the code below:

using (ServerManager serverManager = new ServerManager())
    Configuration config = serverManager.GetApplicationHostConfiguration();
    ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Sharepoint - 80");
    anonymousAuthenticationSection["enabled"] = true;
    anonymousAuthenticationSection["userName"] = txtUserName.Text;
    anonymousAuthenticationSection["password"] = txtPassword.Text;

But now, i came across something that can be a problem. If i try to use this installer on a Sharepoint Farm, the IIS modification will be applied only on that specific server.

Is there a way to achieve the same result, but applying the modification to all servers on the farm using a Event Receiver on my webpart project?

Thanks a lot.


As a good practice, deploying SharePoint customizations should always be done via features, packaged into solutions. This way, SharePoint takes care of the deployment to all web servers in the farm. Of course there are also other benefits such as help with upgrading your features. More info:

Modifying the web.config on every server can also be done via SharePoint: take a look at the SPWebConfigModification class:

You could develop an event receiver that fires when your feature is activated so it makes the web.config modification.

However, In the case of enabling anonymous authentication this should be done via the SharePoint web application settings:

|improve this answer|||||
  • Thank you Thomas, but i don't believe that specific change is kept on the web.config file. I manually changed the options on my IIS Manager and the web.config file of my application didn't have any modifications on it. And reading on the documentation of the ServerManager class, it says that this class initialize the object based on the ApplicationHost.config file. – C. Hoffmann Jan 23 '13 at 20:12

You want to do this with the SPIisSettings class. There is a method in that class called AllowAnonymous which you can set to True and then update the object. That will enable Anon for the Web Application on the specified zone.


|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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