Question

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;
    serverManager.CommitChanges();
}

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.

Was it helpful?

Solution

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:

OTHER TIPS

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.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spiissettings_members.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top