开启或停止website

1、添加:Microsoft.Web.Administration

2、代码:

 static void Main(string[] args)
        {
            var server = new ServerManager();
            var site = server.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
            if (site != null)
            {
                //stop the site...
                site.Stop();
                if (site.State == ObjectState.Stopped)
                {
                    //do deployment tasks...
                }
                else
                {
                    throw new InvalidOperationException("Could not stop website!");
                }
                //restart the site...
                site.Start();
            }
            else
            {
                throw new InvalidOperationException("Could not find website!");
            }
        }

猜你喜欢

转载自www.cnblogs.com/dayang12525/p/10238435.html