开启或停止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!");
            }
        }

 

posted @ 2019-01-08 13:18  向萧  阅读(309)  评论(0编辑  收藏  举报