Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 28058

create a new website on IIS 6 using c#

$
0
0

Hi,

I need to create a new Website programatically on IIS 6. I have used System.DirectoryServices namespace.

I have used the below code to create new website.

 string ipAddress = ipaddress;  //ipAddress of machine whose IIS we are going to access
            string username = username;
            string password = password;
            //you need to supply username and password that has sufficient previllege to access IIS metabase

            DirectoryEntry w3svc = new DirectoryEntry(String.Format("IIS://{0}/W3SVC", ipAddress), username, password);
            DirectoryEntries sites = w3svc.Children;

            //Add new website
            DirectoryEntry siteDE = sites.Add("websiteIdentifier", (w3svc.SchemaClassName.Replace("Service", "Server")));
            //replace "websiteIdentifier" with some uniqueId

            //The ServerComment property specifies a comment for the website instance.
            siteDE.Properties["ServerComment"][0] = "testing";

            //Commit Changes
            siteDE.CommitChanges();
            DirectoryEntry siteRootDE = new DirectoryEntry();
            //Set other metabase properties
            siteRootDE = siteDE.Children.Add("Root", "IIsWebVirtualDir");
            siteRootDE.Properties["AppFriendlyName"][0] = "websiteName";
            siteRootDE.Properties["Path"][0] = @"\\Shared\Website1";
            siteRootDE.Properties["AuthNTLM"][0] = true;

            //if UNC Path is set, specify the username and password
            siteRootDE.Properties["UNCUserName"][0] = "username";
            siteRootDE.Properties["UNCPassword"][0] = "password";
            siteRootDE.Properties["AccessScript"][0] = true;
            siteRootDE.Properties["AccessFlags"][0] = 513;
            //siteRootDE.Properties["AppPoolId"].Value = GetAppPoolAssigment(siteDE);
            //SetASPNetVersion(siteDE);
            siteRootDE.Invoke("AppCreate", 1);
            siteRootDE.CommitChanges();

            //find retrieve the website we have just created and start it
            siteDE = new DirectoryEntry(string.Format(@"IIS://{0}/W3SVC/{1}", ipAddress, "websiteIdentifier"), username, password);
            siteDE.Invoke("Start", null);


But I am getting the exception Unknown error (0x80005000) at the line - DirectoryEntry siteDE = sites.Add("websiteIdentifier", (w3svc.SchemaClassName.Replace("Service", "Server")));


Please do needful regarding this exception.


 


Viewing all articles
Browse latest Browse all 28058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>