.net重啟iis線程池和iis站點(diǎn)程序代碼分享
重啟站點(diǎn):
/// <summary>
/// 根據(jù)名字重啟站點(diǎn).(沒(méi)重啟線程池)
/// </summary>
/// <param name="sitename"></param>
static void RestartWEbSite(string sitename)
{
try
{
var server = new ServerManager();
var site = server.Sites.FirstOrDefault(s => s.Name == sitename);
if (site != null)
{
site.Stop();
if (site.State == ObjectState.Stopped)
{
}
else
{
Console.WriteLine("Could not stop website!");
throw new InvalidOperationException("Could not stop website!");
}
site.Start();
}
else
{
Console.WriteLine("Could not find website!");
throw new InvalidOperationException("Could not find website!");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
/// <summary>
/// 重啟完之后.要再檢測(cè)下.是否開(kāi)啟了
/// </summary>
/// <param name="sitename"></param>
static void FixWebsite(string sitename)
{
try
{
var server = new ServerManager();
var site = server.Sites.FirstOrDefault(s => s.Name == sitename);
if (site != null)
{
if (site.State != ObjectState.Started)
{
Thread.Sleep(500);
//防止?fàn)顟B(tài)為正在開(kāi)啟
if (site.State != ObjectState.Started)
{
site.Start();
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
重啟iis線程池:
/// <summary>
/// 線程池名字
/// </summary>
/// <param name="name"></param>
static void RestartIISPool(string name)
{
string[] cmds = { "c:", @"cd %windir%\system32\inetsrv", string.Format("appcmd stop apppool /apppool.name:{0}", name), string.Format("appcmd start apppool /apppool.name:{0}", name) };
Cmd(cmds);
CloseProcess("cmd.exe");
}
/// <summary>
/// 運(yùn)行CMD命令
/// </summary>
/// <param name="cmd">命令</param>
/// <returns></returns>
public static string Cmd(string[] cmd)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.AutoFlush = true;
for (int i = 0; i < cmd.Length; i++)
{
p.StandardInput.WriteLine(cmd[i]);
}
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
//Debug.Print(strRst);
p.WaitForExit();
p.Close();
return strRst;
}
/// <summary>
/// 關(guān)閉進(jìn)程
/// </summary>
/// <param name="ProcName">進(jìn)程名稱</param>
/// <returns></returns>
public static bool CloseProcess(string ProcName)
{
bool result = false;
var procList = new ArrayList();
foreach (Process thisProc in Process.GetProcesses())
{
var tempName = thisProc.ToString();
int begpos = tempName.IndexOf("(") + 1;
int endpos = tempName.IndexOf(")");
tempName = tempName.Substring(begpos, endpos - begpos);
procList.Add(tempName);
if (tempName == ProcName)
{
if (!thisProc.CloseMainWindow())
thisProc.Kill(); // 當(dāng)發(fā)送關(guān)閉窗口命令無(wú)效時(shí)強(qiáng)行結(jié)束進(jìn)程
result = true;
}
}
return result;
}
相關(guān)文章
.NET Core利用skiasharp文字頭像生成方法教程(基于docker發(fā)布)
這篇文章主要給大家介紹了關(guān)于.NET Core利用skiasharp文字頭像生成(基于docker發(fā)布)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03Asp.Net Core對(duì)接釘釘群機(jī)器人的完整步驟記錄
這篇文章主要給大家介紹了關(guān)于Asp.Net Core對(duì)接釘釘群機(jī)器人的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03Asp.net SignalR 讓實(shí)時(shí)通訊變得如此簡(jiǎn)單
下面小編就為大家分享一篇Asp.net SignalR 讓實(shí)時(shí)通訊變得如此簡(jiǎn)單,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01.NET Core跨平臺(tái)串口通訊使用SerialPortStream基礎(chǔ)類庫(kù)問(wèn)題解決
這篇文章介紹了.NET Core跨平臺(tái)串口通訊使用SerialPortStream基礎(chǔ)類庫(kù)問(wèn)題解決,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01使用DataGrid中擴(kuò)展ItemRenderer和HeaderRenderer進(jìn)行操作
這兩天在用Flex DataGrid做點(diǎn)東西,走了不少?gòu)澛罚F(xiàn)將心得分享一下。2009-02-02asp.net sqlconnection con.close和con.dispose區(qū)別
con.close是用來(lái)關(guān)閉和數(shù)據(jù)庫(kù)的連接,相對(duì)于open2008-12-12.NET使用js制作百度搜索下拉提示效果(不是局部刷新)實(shí)現(xiàn)思路
搞了個(gè)不是局部刷新的百度搜索框下拉提示效果大致思路:前臺(tái)放一個(gè)input標(biāo)簽,然后當(dāng)該標(biāo)簽內(nèi)的值輸入有變化的時(shí)候,調(diào)用后臺(tái)代碼查詢 符合條件的數(shù)據(jù)綁定ListBox,感興趣的朋友可以了解下2013-01-01