C#中如何调用服务器上的IIS上某个指定的站点重启

C#中如何调用服务器上的IIS上某个指定的站点重启,第1张

直接给你一个现成代码吧,实测套用后可行,直接将站点链接输进去就行:

using JinherAMPBTPDeploy;

using MicrosoftWebAdministration;

using RedisHelper;

using System;

using SystemCollectionsGeneric;

using SystemConfiguration;

using SystemIO;

using SystemLinq;

using SystemText;

using SystemThreading;

using SystemThreadingTasks;

namespace Redis

{

public class Program

{

static readonly string AppPoolName = ConfigurationManagerAppSettings["ApplicationPoolName"]ToString();

static readonly string WebSiteName = ConfigurationManagerAppSettings["WebSiteName"]ToString();

static readonly int SleepTime = intParse(ConfigurationManagerAppSettings["SleepTime"]ToString());

static ServerManager sm;

static void Main(string[] args)

{

ConsoleWriteLine($"检测程序启动,{WebSiteName}当网站或其应用池停下后,会自动启动。");

sm = new ServerManager();

new Thread(RecoveryWebSite)Start();

}

static void RecoveryWebSite()

{

while (true)

{

try

{

var pool = smApplicationPools[AppPoolName];

if (pool != null && poolState == ObjectStateStopped)

{

ConsoleWriteLine("检测到应用池" + AppPoolName + "停止服务");

ConsoleWriteLine("正在启动应用池" + AppPoolName);

if (poolStart() == ObjectStateStarted)

{

ConsoleWriteLine("成功启动应用池" + AppPoolName);

}

else

{

ConsoleWriteLine("启动应用池" + AppPoolName + "失败 " + SleepTime / 60 + "秒后重试启动");

}

}

var site = smSites[WebSiteName];

if (site != null && siteState == ObjectStateStopped)

{

ConsoleWriteLine("检测到网站" + WebSiteName + "停止服务");

ConsoleWriteLine("正在启动网站" + WebSiteName);

if (siteStart() == ObjectStateStarted)

{

ConsoleWriteLine("成功启动网站" + WebSiteName);

}

else

{

ConsoleWriteLine("启动网站" + WebSiteName + "失败 " + SleepTime / 60 + "秒后重试启动");

}

}

}

catch (Exception ex)

{

ConsoleWriteLine(exMessageToString());

}

GCCollect();

ThreadSleep(SleepTime);

}

}

}

}

翻译:
服务器已经打开
无法自动确定时区。一个不正确的时区会导致不正确的时间戳日志控制台。它被设置为“UTC”默认情况下。你可以改变它在phpini文件。
线程必须大于或等于209,而你的是208
请使用主页上提供的安装程序,或重新编译PHP
服务器已关闭


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13455627.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-10
下一篇 2023-08-10

发表评论

登录后才能评论

评论列表(0条)

保存