私は現在、新しいAPIでIIS 7.5を構成するようにアプリケーションを調整するために、Microsoft.Web.Administration(MWA)名前空間で遊んでいます。すべてのIISレベルの変更は、次のファイルで表現する必要があることを理解しました(私はWin2K8-R2を使用しています)。
%WINDIR%\ System32 \ inetsrv \ config \ applicationHost.config
したがって、ServerManager
オブジェクトを使用して構成の変更をコミットするときは、それに応じてファイルを更新する必要があります。
新しいMIMEタイプ(MWAを使用してプログラム)を追加した後、に変更は見られませんでしたapplicationHost.config file
が、IISマネージャーウィンドウに新しいMIMEタイプが表示され、IISはこのMIMEタイプを問題なく認識します。OSを再記述した後でも-構成ファイルには新しく追加されたMIMEタイプは含まれていませんが、IISマネージャーウィンドウにはリストされています。
私のアプリケーションプールは32ビット(Enable32BitAppOnWin64 = true
)に強制されているので、関連する構成ファイルはの下に配置する必要があると思いました%WINDIR%\SysWOW64\inetsrv\Config
が、(存在する場合は...)-コードが更新をコミットした後も変更されません。
誰かがこれを説明できますか?私は何かが足りませんか(おそらく間違ったファイルを見ていますか?)?SysWOW64\inetsrv\config
誰かがディレクトリに光を当ててくれませんか?
これは、MIMEタイプを追加するための私のコードです。
ServerManager manager = new ServerManager();
ConfigurationElementCollection staticContentCollection = manager
.GetApplicationHostConfiguration()
.GetSection("system.webServer/staticContent")
.GetCollection();
//MIMETypes is a string[] array, each object is {FileExt},{MIMETypeStr}
foreach (string pair in MIMETypes)
{
string[] mimeProps = pair.Split(',');
ConfigurationElement mimeTypeEl = staticContentCollection
.Where(a =>
(string)a.Attributes["fileExtension"].Value == mimeProps[0])
.FirstOrDefault();
if (mimeTypeEl != null)
{
staticContentCollection.Remove(mimeTypeEl);
}
ConfigurationElement mimeMapElement =
staticContentCollection.CreateElement("mimeMap");
mimeMapElement["fileExtension"] = mimeProps[0];
mimeMapElement["mimeType"] = mimeProps[1];
staticContentCollection.Add(mimeMapElement);
}
manager.CommitChanges();
//At this point all is working but the config file does not reflect the change