c# を使用して IIS 7 のプログラムを使用して Web サイトを展開しようとしています。
アプリケーションをデフォルトの Web サイトにデプロイしたいと考えています。
アプリケーションには、既定の Web サイトの他のアプリケーションとは別のポート番号 (90)、または既定の Web サイトの既定のポート番号 (つまり 8080 ) が必要です。
Web サイトのweb.configファイルにバインディング情報を指定せずに、ServerManagerクラスを使用してこれをプログラムで実行しようとしています。
static void CreateSite()
{
using (ServerManager server = new ServerManager())
{
if (server.Sites != null && server.Sites.Count > 0)
{
Site defaultsite=server.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
if (defaultsite != null)
{
string path = @"C:\inetpub\wwwroot\MyApp\";
//specify the Binding information
string ip = "*";
string port = "90";
string hostName = "*";
string bindingInfo = string.Format(@"{0}:{1}:{2}", ip, port, hostName);
defaultsite.Applications.Add("/MyApp", path);
server.CommitChanges();
}
}
}
}
ServerManager クラスを使用すると、以下のように、サイトの下の各アプリケーションではなく、各サイトのバインドを作成/更新/削除できます。
string ip = "*";
string port = "90";
string hostName = "*";
string bindingInfo = string.Format(@"{0}:{1}:{2}", ip, port, hostName);
BindingCollection bindingCollection = defaultsite.Bindings;
Binding binding = defaultsite.Bindings.CreateElement("binding");
binding["protocol"] = "http";
binding["bindingInformation"] = bindingInfo;
bindingCollection.Add(binding);
server.CommitChanges();
ServerManager クラス メソッドを使用して、IIS 7.0 でアプリケーションに別のポート番号を指定するにはどうすればよいですか?