有关ADSI的问题!
利用ADSI建立一个站点,在IIS中是可以看到该站点,且该站点可以被访问,但利用代码却找不到这个站点.当机器重启之后,相同的代码就可以找到该站点了.高手指点:为什么在站点刚被建立之后利用代码却找不到该站点?
相关代码如下:
string siteName = GetNewSiteID() ;
object[] prams = new object[2]{"IIsWebServer",Convert.ToInt32( siteName ) } ;
DirectoryEntry site = (DirectoryEntry)directoryEntry.Invoke( "Create" , prams ) ;
site.Properties["KeyType"][0] = "IIsWebServer" ;
site.Properties["ServerComment"][0] = siteInfo.ServerComment ;
site.Properties["ServerBindings"].Add( ":" + siteInfo.ServerBindings + ":" ) ;
site.Properties["ServerState"][0] = int.Parse( siteInfo.ServerState.ToString() ) ;
site.Properties["ServerSize"][0] = 1 ;
site.Properties["AspEnableParentPaths"][0] = 1 ;
site.Properties["AspScriptLanguage"][0] = siteInfo.AspScriptLanguage.ToString() ;
site.CommitChanges() ; // 保存改变
directoryEntry.CommitChanges() ;
directoryEntry.RefreshCache() ;
DirectoryEntry root = site.Children.Add("Root","IIsWebVirtualDir") ;
root.Invoke("AppCreate",true) ; // 创建IIS应用程序
root.Properties["path"][0] = siteInfo.Path ; //虚拟目录指向的物理目录
root.Properties["EnableDirBrowsing"][0] = false ;
root.Properties["AuthAnonymous"][0] = true ;
root.Properties["AccessExecute"][0] = false ;
root.Properties["AccessRead"][0] = true ;
root.Properties["AccessWrite"][0] = false ;
root.Properties["AccessScript"][0] = true ;
root.Properties["AccessSource"][0] = false ;
root.Properties["FrontPageWeb"][0] = false ;
root.Properties["KeyType"][0] = "IIsWebVirtualDir" ;
root.Properties["AppFriendlyName"][0] ="默认应用程序" ;
root.Properties["AppIsolated"][0] = 2 ;
root.Properties["DefaultDoc"][0] = siteInfo.DefaultDoc ;
root.Properties["EnableDefaultDoc"][0] = true ;
root.CommitChanges() ;
site.CommitChanges() ;
root.RefreshCache() ;
site.RefreshCache() ;
directoryEntry.CommitChanges() ;
directoryEntry.RefreshCache() ;