我想将MIME类型添加到新创建的虚拟目录中,该目录位于“默认网站”下。
using (ServerManager manager = new ServerManager())
{
ServerManager manager = new ServerManager();
var vdir = manager.Sites["Default Web Site"].Applications["/"].VirtualDirectories["VDir"];
}
我没有找到适当的示例/文档,我可以在不使用DirectoryServices
的情况下为虚拟目录(而不是网站)找到它。有什么建议吗?
答案 0 :(得分:1)
您是否尝试过这样做(稍微修改the example on IIS.NET):
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration vDirConfig = serverManager.GetWebConfiguration("Default Web Site", "/VDir");
ConfigurationSection staticContentSection = vDirConfig.GetSection("system.webServer/staticContent");
ConfigurationElementCollection staticContentCollection = staticContentSection.GetCollection();
ConfigurationElement mimeMapElement = staticContentCollection.CreateElement("mimeMap");
mimeMapElement["fileExtension"] = @"bla";
mimeMapElement["mimeType"] = @"application/blabla";
staticContentCollection.Add(mimeMapElement);
ConfigurationElement mimeMapElement1 = staticContentCollection.CreateElement("mimeMap");
mimeMapElement1["fileExtension"] = @"tab";
mimeMapElement1["mimeType"] = @"text/plain";
staticContentCollection.Add(mimeMapElement1);
serverManager.CommitChanges();
}
}
}