I am trying to create a site in IIS using Microsoft.Web.Administration dll in C#. I am using following code
我正在尝试使用Microsoft.Web在IIS中创建一个站点。*在c# dll。我正在使用以下代码
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
当我在asp.net项目中运行代码时,我得到了以下异常“方法或操作未实现”,但是如果在控制台项目中运行相同的代码,那么它会工作得很好。这里是例外的细节。
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
似乎是权利的问题,但我不知道如何解决它。更新1:在本地主机上执行以下代码行错误。
site.Bindings.Add(httpsBindingInformation, httpsProtocol);
1 个解决方案
#1
1
I think you're trying to set the same bindings twice :
我想你是想把相同的绑定设置两次:
- Once by calling the Add method
- 调用Add方法一次
Site site = serverManager.Sites.Add(SiteName, httpProtocol, httpBindingInformation, physicalPath);
网站网站= serverManager.Sites。Add(SiteName、httpProtocol httpBindingInformation physicalPath);
- Then you add again the same binding:
- 然后再添加相同的绑定:
site.Bindings.Add(httpsBindingInformation, httpsProtocol);
site.Bindings。Add(httpsBindingInformation httpsProtocol);
#1
1
I think you're trying to set the same bindings twice :
我想你是想把相同的绑定设置两次:
- Once by calling the Add method
- 调用Add方法一次
Site site = serverManager.Sites.Add(SiteName, httpProtocol, httpBindingInformation, physicalPath);
网站网站= serverManager.Sites。Add(SiteName、httpProtocol httpBindingInformation physicalPath);
- Then you add again the same binding:
- 然后再添加相同的绑定:
site.Bindings.Add(httpsBindingInformation, httpsProtocol);
site.Bindings。Add(httpsBindingInformation httpsProtocol);