gpt4 book ai didi

asp.net - 使用 DirectoryEntry 和 C# 启动/停止 IIS 应用程序池需要哪些访问权限?

转载 作者:行者123 更新时间:2023-12-02 03:58:37 24 4
gpt4 key购买 nike

鉴于以下方法,我正在尝试启动/停止 IIS 7 应用程序池。我可以在本地系统上成功完成此操作,但是当我将其放在我们的 Windows 2008 服务器上时,仅在尝试停止服务时才会收到错误 - 启动工作正常:

[NoCache]
public ActionResult EnableAppPool(Models.ActionRequest actionRequest)
{
try
{
if (ModelState.IsValid && actionRequest.ActionRequestPassword == ConfigurationManager.AppSettings["NewsfeedAdminPassword"])
{
bool enableNewsfeed = false;
enableNewsfeed = Convert.ToBoolean(actionRequest.EnableNewsfeedAppPool);

string sPath = "IIS://" + ConfigurationManager.AppSettings["MachineName"] + "/W3SVC/AppPools/" + ConfigurationManager.AppSettings["AppPoolName"];
Console.WriteLine(sPath);
DirectoryEntry w3svc = new DirectoryEntry(sPath);
if (enableNewsfeed)
{
w3svc.Invoke("Start");
}
else
{
w3svc.Invoke("Stop");
}
}
}
catch (Exception ex)
{
throw ex;
}

return null;
}

错误如下:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.



我意识到这是一个权限问题,但我不确定我必须授予访问权限以及授予什么用户权限。

仅供引用:我已经启用了 IIS 6 元数据库和 WMI 兼容性

最佳答案

您运行代码的身份无权启动和停止应用程序池。这是一篇文章的引述

“为了与 Active Directory 通信,必须考虑网络安全、业务规则和技术限制。如果您使用 ASP.NET 页面中的 Active Directory 代码,则必须确保代码具有适当级别的权限以访问目录并与之交互。出于开发目的或概念验证,您可以在 ASP.NET 级别(在 web.config 中)和 IIS 级别启用模拟,如果 IIS 服务器和目录域 Controller 位于同一台机器上,则此但是,如果这些实体不在同一台服务器上(因为它们从未在生产中),您可以将代码包装在模拟类周围(例如 Zeta Impersonator,它将在 token 下执行目录调用冒充用户。”

http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#3

这篇文章清楚地解释了如何在差异(可能是更高级别的访问用户)上下文下在您的应用程序中运行一些代码。

http://support.microsoft.com/kb/306158

关于asp.net - 使用 DirectoryEntry 和 C# 启动/停止 IIS 应用程序池需要哪些访问权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11463135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com