3

I am trying to create a site in IIS using Microsoft.Web.Administration dll in C#. I am using following code

using (var serverManager = new ServerManager())
        {
            ApplicationPool pool = serverManager.ApplicationPools.Add(ClientDomain);
            pool.ManagedRuntimeVersion = "v4.0";
            Site site = serverManager.Sites.Add(SiteName, httpProtocol, httpBindingInformation, physicalPath);
            site.Bindings.Add(httpsBindingInformation, httpsProtocol);
            serverManager.CommitChanges();
        }

I am getting following exception "The method or operation is not implemented" when I run the code from asp.net project but if same code is run from console project, it works fine. Here is the details of the exception

   at Microsoft.Web.Administration.Interop.IAppHostProperty.get_Value()
   at Microsoft.Web.Administration.ConfigurationElement.GetPropertyValue(IAppHostProperty property)
   at Microsoft.Web.Administration.ConfigurationElement.GetAttributeValue(String attributeName)
   at Microsoft.Web.Administration.Binding.get_CertificateHash()
   at Microsoft.Web.Administration.BindingCollection.Add(Binding binding)
   at Microsoft.Web.Administration.BindingCollection.Add(String bindingInformation, String bindingProtocol)
   at TestProject.BLL.CRMSiteManagement.CRMSiteIISSetup.Process() in e:\CRMSiteManagement\CRMSiteIISSetup.cs:line 35
   at TestProject.BLL.CRMSiteManagement.CRMSiteService.CreateNewCRMSite(CRMSite newSite) in e:CRMSiteManagement\CRMSiteService.cs:line

Seems like an issue with rights but I have not idea how to fix it. Update 1: Error is coming on following line of code on localhost

site.Bindings.Add(httpsBindingInformation, httpsProtocol); 
1

1 Answer 1

1

I think you're trying to set the same bindings twice :

  1. Once by calling the Add method

Site site = serverManager.Sites.Add(SiteName, httpProtocol, httpBindingInformation, physicalPath);

  1. Then you add again the same binding:

site.Bindings.Add(httpsBindingInformation, httpsProtocol);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.