質問

Having troubles when i want to create a new server using servermanager.

Here's my code



    ServerManager sm = new ServerManager();
    Site s = sm.Sites.Add("NEWSERVER", path, 80);

    BindingCollection bindingCollection = s.Bindings;
    bindingCollection.Clear();

    Binding binding = s.Bindings.CreateElement("binding");
    binding["protocol"] = "https";
    binding["certificateHash"] = "‎thumprint value";
    binding["certificateStoreName"] = "MY";
    binding["bindingInformation"] = string.Format("{0}:{1}:{2}", "*", "443", "subdomain.url.com");
    bindingCollection.Add(binding);

    Binding binding2 = s.Bindings.CreateElement("binding");
    binding2["protocol"] = "http";
    binding2["bindingInformation"] = string.Format("{0}:{1}:{2}", "*", "80", "subdomain.url.com");
    bindingCollection.Add(binding2);

    s.ServerAutoStart = true;

    ApplicationPool a = sm.ApplicationPools.Add("NEWSERVER");
    a.ManagedRuntimeVersion = "v4.0";
    s.ApplicationDefaults.ApplicationPoolName = "NEWSERVER";
    sm.CommitChanges();

When i run it, it creates server + bindings, but it gives the following error:

"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

which occurs when sm.CommitChnages() is run.

I can't figure out which what i don't have access to. Any ideas?

役に立ちましたか?

解決

You have to run this piece of code with a local administrator account.

For ASP.NET applications, your choices are

  1. Impersonate as a local administrator using WindowsIdentity.
  2. Or run the application pool under a local administrator account.

Both of them have something you need to pay attention to on security side,

http://msdn.microsoft.com/en-us/library/ff647404.aspx

他のヒント

I have same issue while trying to add binding dynamically. I just ran application as Administrator

Its worked for me.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top