2010-12-16 7 views
1

C#を使用してIIS 6で仮想ディレクトリを作成しています。C#を使用しているIIS 6の仮想ディレクトリのアプリケーション名は空のままです。

仮想ディレクトリを作成できましたが、[アプリケーション名]フィールドは空のままです。

alt text

ここで私は

のDirectoryEntry iisRoot =新しい のDirectoryEntry( "IIS://" + Environment.MachineName + "/ W3SVC")を使用していますコードです。

文字列webName = "1";

文字列virdir = "TestApp1";

文字列installpath = @ "C:\ MyWeb \ Application \";

 try 
     { 
      string iisPath = string.Format("IIS://{0}/W3SVC/{1}/Root", Environment.MachineName, webName); 
      Console.WriteLine(iisPath); 
      iisRoot = new DirectoryEntry(iisPath); 

      DirectoryEntry vdir = iisRoot.Children.Add(virdir, iisRoot.SchemaClassName); 

      vdir.Properties["Path"][0] = installpath; 
      vdir.Properties["AppFriendlyName"][0] = virdir; 
      vdir.Properties["EnableDefaultDoc"][0] = true; 
      vdir.Properties["DefaultDoc"][0] = "Login.aspx,default.htm,default.aspx,default.asp"; 
      vdir.Properties["AspEnableParentPaths"][0] = true; 
      vdir.CommitChanges(); 
      vdir.Invoke("AppCreate", true); 
     } 
     catch (Exception e) 
     { 
      Console.Write(e.Message + "\n" + e.StackTrace); 
     } 

私は「AppFriendlyName」プロパティを使用していたが、まだそれは、仮想ディレクトリのプロパティに表示されません。

+0

あなたは*の作業*アプリの 'DirectoryEntry'を取得し、プロパティを調べることができすべきですか? –

+0

プロパティにアクセスしようとしましたが、「AppFriendlyName」が空白(空)になっています –

答えて

2

最後に私は答えを得ました。

'AppFriendlyName'プロパティは、vdir.CommitChanges()の後に設定する必要があります。

ので、コードが

DirectoryEntry iisRoot = new DirectoryEntry("IIS://" + Environment.MachineName + "/W3SVC"); 

string webName = "1"; 

string virdir = "TestApp1"; 

string installpath = @"C:\MyWeb\Application\"; 

     try 
     { 
      string iisPath = string.Format("IIS://{0}/W3SVC/{1}/Root", Environment.MachineName, webName); 
      Console.WriteLine(iisPath); 
      iisRoot = new DirectoryEntry(iisPath); 

      DirectoryEntry vdir = iisRoot.Children.Add(virdir, iisRoot.SchemaClassName); 

      vdir.Properties["Path"][0] = installpath; 
      vdir.Properties["EnableDefaultDoc"][0] = true; 
      vdir.Properties["DefaultDoc"][0] = "Login.aspx,default.htm,default.aspx,default.asp"; 
      vdir.Properties["AspEnableParentPaths"][0] = true; 
      vdir.CommitChanges(); 
      vdir.Invoke("AppCreate", true); 
      vdir.Properties["AppFriendlyName"][0] = virdir; 
      vdir.CommitChanges(); 
     } 
     catch (Exception e) 
     { 
      Console.Write(e.Message + "\n" + e.StackTrace); 
     } 
0

AppFriendlyNameは、IIS 6 documentationとして設定するプロパティです。おそらく、あなたはvdir.Properties["AppFriendlyName"].Value = "Some Name";を試すことができます。

+0

私は同じだが成功しなかった。とにかく最終的にいくつかのテストと調整をして、私は答えを得ました。 –

+0

@Sunil、他の人たちと同じことを共有してみませんか?いつか誰かを助けるかもしれません! – VinayC

+0

はい答えを掲載しました。しかし、私はなぜそうなのか分からない –

関連する問題