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);

}

}

}

}

public class MDUser{
static {
SystemloadLibrary("MDUserCOM");
}
public native void AddUser(String fileName);
}


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

原文地址:https://54852.com/zz/10898200.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存