Tag Archive: IIS


Recently I joined a new website hosting provider who supported WebMatrix and MVC. After I used Web Deploy to upload my working files to the server, I got 404 errors on some of the pages. After some investigation I realized that I had to specify the full cshtml file extension on all links. After doing some research, Rick Strahl once again saved my life. In his blog entry, he explained that the following line of code must be added to web.config, if hosted on IIS 7, for routing to work.

<modules runAllManagedModulesForAllRequests="true">

Who would have thought of that?

The following example demonstrates how to disable anonymous authentication in IIS, and enable windows authentication.


using (ServerManager serverManager = new ServerManager())
{
Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration();
Microsoft.Web.Administration.ConfigurationSection anonymousAuthenticationSection = config.GetSection
("system.webServer/security/authentication/anonymousAuthentication", webSiteName + "/" + applicationName);
anonymousAuthenticationSection["enabled"] = false;
Microsoft.Web.Administration.ConfigurationSection windowsAuthenticationSection = config.GetSection
("system.webServer/security/authentication/windowsAuthentication", webSiteName + "/" + applicationName);
windowsAuthenticationSection["enabled"] = true;
serverManager.CommitChanges();
}