开发者

Application Name remain empty for virtual directory in IIS 6 using C#

开发者 https://www.devze.com 2023-01-31 01:45 出处:网络
I am creating virtual directory in IIS 6 using C#. I am able to create the virtual directory but the \'Application Name\' field remains empty.

I am creating virtual directory in IIS 6 using C#.

I am able to create the virtual directory but the 'Application Name' field remains empty.

Application Name remain empty for virtual directory in IIS 6 using C#

Here's the code I am using

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["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);
        }

I have used 'AppFriendlyName' property but still it does not show up in virtual directory properties.


Finally I got the answer.

The 'AppFriendlyName' property must nbe set after the vdir.CommitChanges();

so the code should be

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);
        }


AppFriendlyName is the property to be set as per IIS 6 documentation. Perhaps, you can try vdir.Properties["AppFriendlyName"].Value = "Some Name";.

0

精彩评论

暂无评论...
验证码 换一张
取 消