日期:2014-05-17  浏览次数:20840 次

c# 如何修改IIS站点的行为?
   string constIISWebSiteRoot = "IIS://localhost/W3SVC/14/ROOT";
            DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);
            DirectoryEntry tbEntry = root.Children.Add(appName, "IIsWebVirtualDir");
            tbEntry.Properties["Path"][0] = physicalPath;  //虚拟目录物理路径
            tbEntry.Invoke("AppCreate", true);//删除tbEntry.Invoke("AppDelete",true);   tbEntry.CommitChanges();              
            tbEntry.Properties["AccessRead"][0] = true;   //设置读取权限
            tbEntry.Properties["ContentIndexed"][0] = true;
            tbEntry.Properties["DefaultDoc"][0] = "index.aspx,Default.aspx"; //设置默认文档,多值情况下中间用逗号分割
            tbEntry.Properties["AppFriendlyName"][0] = appName; //虚拟目录名称:Monitor
            tbEntry.Properties["AccessScript"][0] = true; //执行权限[純腳本]
            tbEntry.Properties["AppIsolated"][0] = "1";//属性指出应用程序是在进程内、进程外还是在进程池中运行。值 0 表示应用程序在进程内运行,值 1 表示进程外,值 2 表示进程池。
            tbEntry.Properties["DontLog"][0] = true;  // 是否记录日志               
            tbEntry.Properties["AuthFlags"][0] = 0;
          tbEntry.CommitChanges();


修改IIS的属性是可以的,可我找不到修改 行为(已启用的协议)



下面这句修改不了~
tbEntry.Properties["protocol"][0] = "http,net.tcp";

------解决方案--------------------
试试 
/// <summary>
        /// 修改IIS站点虚拟目录的行为
        /// </summary>
        /// <param name="siteName">站点名称</param>
        /// <param name="appName">虚拟站点名称</param>
        private void UpdateProtocol(string siteName, string appName)
        {
            using (ServerManager iisManager = new ServerManager())
            {
                Site site = iisManager.Sites[siteName];
                if (site != null)
          &nbs