Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:07:41+00:00 2026-06-11T01:07:41+00:00

Context I use the ServerManager class to perform some actions on sites. Actually, I

  • 0

Context

I use the ServerManager class to perform some actions on sites.

Actually, I delete bindings (http/https) on a site1 and I recreate it on a site2.

I save changes with .CommitChanges().

After that, the issue is that IIS turns off the site. So I use site2.Start() to restart the site.

But this doesn’t work… except if I put a breakpoint on site2.Start().

Any idea of ​​what’s going on? Do you have a solution?

Full code (restart in the last line)

var serverManager = new ServerManager();
var regex = new Regex("^(http|https)://");
var host = regex.Replace(url, "");
var instance = serverManager.Sites.First(site => site.Bindings.Any(binding => binding.Host == host));
var pool = instance.Applications[0].ApplicationPoolName;
var bindingHttp = instance.Bindings.First(attr => attr.Host == host && attr.Protocol == "http");
var bindingHttps = !host.Contains("xxx") ? instance.Bindings.First(attr => attr.Host == host && attr.Protocol == "https") : null;
var bindingHttpInformation = bindingHttp.BindingInformation;
var bindingHttpsInformation = !host.Contains("xxx") ? bindingHttps.BindingInformation : null;
var certificateHash = !host.Contains("xxx") ? bindingHttps.CertificateHash : null;
var certificateStoreName = !host.Contains("xxx") ? bindingHttps.CertificateStoreName : null;
var newSiteName = getPoolOrSiteName(pool);
var newSite = serverManager.Sites.First(attr => attr.Name == newSiteName);
var bindingCollection = newSite.Bindings;

instance.Bindings.Remove(bindingHttp);

if (!host.Contains("xxx"))
{
    instance.Bindings.Remove(bindingHttps);

    var binding = newSite.Bindings.CreateElement("binding");
    binding["protocol"] = "https";
    binding["certificateHash"] = certificateHash;
    binding["certificateStoreName"] = certificateStoreName;
    binding["bindingInformation"] = bindingHttpsInformation;
    bindingCollection.Add(binding);
}

var binding2 = newSite.Bindings.CreateElement("binding");
binding2["protocol"] = "http";
binding2["bindingInformation"] = bindingHttpInformation;
bindingCollection.Add(binding2);

serverManager.CommitChanges();

newSite.Start(); //only works if I put a breakpoint here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:07:42+00:00Added an answer on June 11, 2026 at 1:07 am

    I think it’s a timing issue. It’s the same when you stop a site with the IIS Management console and you subsequently try to start it. You have to give it some time to finish stopping. So a (warning: ugly) sleep could probably do:

    System.Threading.Thread.Sleep(5000);
    

    The fact that it works when debugging, is because you give it the delay before you proceed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use Context.Items to store some info of a User Control like:
Context I want to use JavaFx with clojure. I am aware of http://nailthatbug.net/2011/06/clojure-javafx-2-0-simple-app/ Question:
Could anyone please explain what context should i use the AlertDialog.Builder class? I am
Context: I use an ArrayCollection object as follows: 1) Number of elements is fixed.
the context i use Spooler Events API to capture events generated by the spooler
I'm working on a project that is trying to use context-free grammars for parsing
I choose an item in my list to edit (I use Context Menu) ,
I am making an application which makes use of context menus and has selection.
I'm having trouble understanding why I would use a context.xml file to declare a
I got a little confusing situation here when I use the Context from django.template.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.