从它自己的线程停止IIS网站 [英] Stop IIS website from its own thread

查看:206
本文介绍了从它自己的线程停止IIS网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用下面的代码,以阻止其自己的线程我的WCF服务,以更新由我的服务所使用的一些文件。



<前类=郎-CS prettyprint-覆盖>
{
VAR服务器=新ServerManager的();
变种网站= server.Sites.FirstOrDefault(S = GT; s.Name ==默认Web站点);
如果(网站!= NULL)
{
Thread.sleep代码(1000);
site.Stop();
如果(site.State == ObjectState.Stopped)
{
Thread.sleep代码(5000);
}
site.Start();
}
,否则
{
抛出新的FaultException(服务器试图阻止未找到);
}
}
赶上(异常前)
{
抛出新的FaultException(ex.Message);
}



但是,当我执行的代码我得到以下错误:




访问被拒绝(异常来自HRESULT:0X80070005(E_ACCESSDENIED))。



< DIV CLASS =h2_lin>解决方案

我觉得你应该运行PowerShell脚本这样的情况下,你要停止的过程,是自我的我明白了。这意味着停止后,你的进程将被杀死,并可以进行任何更新。随着电源外壳,你可以停止过程中,复制了文件,并开始了



 导入模块WebAdministration 
停止-网站默认Web站点
#...复制文件在这里
启动网站默认Web站点


I am using the following code to stop my WCF service from its own thread to update some files that are used by my service.

try
{
    var server = new ServerManager();
    var site = server.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
    if (site != null)
    {
        Thread.Sleep(1000);
        site.Stop();
        if (site.State == ObjectState.Stopped)
        {
            Thread.Sleep(5000);
        }
        site.Start();
    }
    else
    {
        throw new FaultException("Server Are Trying To Stop Is not Found");
    }
}
catch (Exception ex)
{
    throw new FaultException(ex.Message);
}

But I get following error when I execute the code:

"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

解决方案

I think you should run Powershell script for such case, as you want to stop the process which is self as I understand. Meaning that after stop, your process will be killed and no update can be performed. With power shell you could stop process, copy over files and start over

Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
#... copy files here
Start-WebSite 'Default Web Site'

这篇关于从它自己的线程停止IIS网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆