当 AppPool 在 LocalSystem 或 LocalService 帐户下运行时,从 ASP.NET 应用程序重新启动服务器

发布于 2024-12-18 03:02:09 字数 262 浏览 1 评论 0原文

是否可以从 LocalSystem 或 LocalService 帐户托管的 ASP.NET 应用程序重新启动服务器?当我创建自定义管理帐户并将 AppPool 在该帐户下运行时,这是有效的:

Process.Start("shutdown", "/r /d 4:1 /t 10");

但是,我不想拥有自定义帐户(因为密码过期,并且需要在用户密码更改时更新所有 AppPools - 我需要维护多个服务器)。

那么,这可能吗?

Is it possible to restart server from ASP.NET application that is hosted by LocalSystem or LocalService account? This is working when I create custom administrative account and put AppPool to run under that account:

Process.Start("shutdown", "/r /d 4:1 /t 10");

However, I don't want to have custom accounts (because of password expiry and need to update all AppPools when User passwords are changed - I need to maintain multiple servers).

So, is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

非要怀念 2024-12-25 03:02:09

您始终可以使用可以重新启动服务器的不同身份来启动该进程:

var info = new ProcessStartInfo("shutdown.exe", "/r /t 0");
info.UserName = "accountWithAdminPermissions";
//A not-so-secure use of SecureString
var secureString = new SecureString();
var password = "abc123";
foreach (var letter in password)
{
    secureString.AppendChar(letter);
}
info.Password = secureString;
var restart = new Process();
restart.StartInfo = info;
restart.Start();

如果您只想授予非管理帐户重新启动服务器的权限:

  1. 打开 secpol.msc
  2. 导航到本地策略\用户权限分配。
  3. 找到关闭系统
  4. 添加帐户。

这可能是使用帐户最小权限的好方法。这样您就不必使用像管理员组中的帐户这样的大锤子。

Shutdown.exe(我相信)始终需要管理员权限。您可以参考这篇MSDN帖子 在没有 shutdown.exe 的情况下重新启动服务器。

You can always start the process with a different identity that can restart the server:

var info = new ProcessStartInfo("shutdown.exe", "/r /t 0");
info.UserName = "accountWithAdminPermissions";
//A not-so-secure use of SecureString
var secureString = new SecureString();
var password = "abc123";
foreach (var letter in password)
{
    secureString.AppendChar(letter);
}
info.Password = secureString;
var restart = new Process();
restart.StartInfo = info;
restart.Start();

If you just want to give a non-Administrative account the permission to restart the server:

  1. Open secpol.msc.
  2. Navigate to Local Policies\User Rights Assignment.
  3. Find Shutdown The System.
  4. Add the account.

This might be a good way of using an account for least privilege. That way you don't have to use a really big hammer like an account in the Administrator group.

Shutdown.exe (I believe) always requires Administrator permissions. You can refer to this MSDN post on restarting the server without shutdown.exe.

千年*琉璃梦 2024-12-25 03:02:09

您可以让代码在拨打该电话时模拟特定帐户,或者使用一个帐户启动一项 Web 服务。我推荐网络服务,最坏的情况是您更新一个应用程序池。您还可以在内部将 Web 服务锁定到仅您的应用程序。

用于模拟用户的小型 C# 类

You could have your code impersonate a specific account when making that call or stand up a web service with one account. I recommend the web service, worst case is you update one app pool. You could also lock down the web service internally to only your applications.

A small C# Class for impersonating a User

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文