Die WebExtensions für das .net 4.0 Framework sind standardmäßig deaktiviert. Der Code aktiviert die Extensions.
/// <summary>
/// Enable the web extension to .net 4.0 framework.
/// </summary>
public void Enable40WebExtension()
{
// enable .net 4.0 processing at isapi/cgi settings in IIS 6
using (var w3svc = new DirectoryEntry("IIS://localhost/W3SVC"))
{
w3svc.RefreshCache();
var extensions = w3svc.Properties["WebSvcExtRestrictionList"];
bool changed = false;
for (int i = 0; i < extensions.Count; i++)
{
string extension = extensions[i].ToString();
if (extension.Contains(@"\Microsoft.NET\Framework\v4.0.30319"))
{
if (extension.IndexOf('0') == 0)
{
extension = "1" + extension.Substring(1);
extensions[i] = extension;
changed = true;
break;
}
}
}
if (changed)
w3svc.CommitChanges();
}
}
Kommentare zum Snippet