我怎样才能“从ASP.NET页面启动/停止窗口服务” [英] How can I "Start/Stop Window Service from ASP.NET page"

查看:71
本文介绍了我怎样才能“从ASP.NET页面启动/停止窗口服务”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述









我可以控制我的电脑服务。 (本地)



我在服务器上发布。我可以看到服务的状态。但是,我无法改变服务状态。



如何更改状态。谢谢!





I can control my computer services. ( Local )

I'm publishing on a server. I can see the status of services. But, I can not change the service status.

How do I make a change in state. Thanks!

推荐答案

首先,我建议你永远不要尝试启动和停止服务。这是由服务控制器完成的,但您无法获得为Web应用程序控制它的权限。通常,Web应用程序在沙盒环境中执行,并且与任何可能危及系统行为的活动完全隔离;这是在常规系统权限之上完成的。还有很多其他原因可以避免它。



相反,您的服务应该始终有效。而不是停止和启动,您必须在应用程序级别上具有不同的服务活动模式:在一种模式下它正常运行,在其他模式下,它正在运行,但其应用程序活动被暂停,其功能可以是减少接受来自管理客户端和来自该客户端的命令的连接,因此其中一个命令可以恢复服务的操作。



我提到上面的管理客户端。您的服务应该包括一些网络服务,我称之为管理客户端。此客户端应连接到服务并发送如上所述的命令。你的代码的某些部分应该实现这样的客户端。反过来,这个客户端应该发送它的命令以响应某个ASP.NET网页上的用户操作,从用户进行适当的身份验证,等等...等等...
-SA
First of all, I suggest you never try to start and stop your service. This is done by a service controller, but you could not get permission for controlling it for your Web application. Normally, Web applications are executed in the sandboxed environment and are well isolated from any activity which could compromise system behavior; and this is done on top of "regular" system permissions. There are many other reasons to avoid it.

Instead, your service should work all the time. Instead of "stopping" and "starting", you have to have different modes in service activity on the application level: in one mode it operates normally, in other mode, it is working, but its application activity is suspended, its functionality can be reduced to accepting the connection from the administrative client and the commands from this client, so one of the commands could resume the operation of the service.

I mentioned administrative client above. Your service should include some, say, network service, used by what I called "administrative client". This client should connect to the service and send commands like those I described above. Some part of your code behind should implement such a client. In turn, this client should send its commands in response to the user action on some ASP.NET Web page, from the user properly authenticated, and so one, and so forth…

—SA


这很可能是由于安全问题,您的asp.net应用程序池用户可能没有足够的权限来启动/停止服务。



首先尝试将应用程序用户设置为管理员用户。如果工作正常,那么你只能模仿这个函数的用户。(否则运行具有高优先级帐户的asp.net网站会更冒险)

this is most probably due to security issue, your asp.net application pool user may not have sufficient rights to Start/Stop a service.

first try to set application user as an administrator user. if that is working fine then you can impersonate user for this function only.(otherwise it will be more risky with running asp.net site with high previleges account)
Quote:

默认情况下,IIS应用程序在ASP.NET帐户下运行,该帐户对窗口服务没有访问权限。因此,解决方案的非常重要的部分是:假冒。您需要使用具有访问窗口服务的适当权限和权限的用户凭据来模拟应用程序/部分代码。

By default, IIS application runs under ASP.NET account which doesn't have access rights permission to window service. So, Very Important part of the solution is: Impersonation. You need to impersonate the application/part of the code with the User Credentials which is having proper rights and permission to access the window service.



关注从ASP.NET页面启动/停止窗口服务 [ ^ ]博客文章。


我做了一个在ASP.NET中使用Windows服务进行项目,这是我对它的总结,希望它可以帮到你: http://codingfarmer.blogspot.com/2014/06/startstop-window-service-from-aspnet.html [ ^ ]
I did a project with windows service in ASP.NET, and this is my summary for it, hope it helps you: http://codingfarmer.blogspot.com/2014/06/startstop-window-service-from-aspnet.html[^]


这篇关于我怎样才能“从ASP.NET页面启动/停止窗口服务”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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