如何将ASP.NET MVC应用程序读取权限授予注册表项?

我已经阅读了有关如何实现这一目标的其他post,但无济于事。 当我将我的应用程序部署到服务器(2008)时,我在运行时收到以下exception:

Access to the registry key 'HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers' is denied. 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 to the registry key 'HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers' is denied. 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) 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. 

要授予对文件的ASP.NET访问权限,请在资源管理器中右键单击该文件,选择“属性”,然后选择“安全”选项卡。 单击“添加”以添加适当的用户或组。 突出显示ASP.NET帐户,并选中所需访问的框。

因此错误似乎非常具有描述性。 我打开regedit并右键单击KEY(HKEY_CURRENT_USER \ Software \ Microsoft) – >权限 – >添加用户’NETWORK SERIVCE’并授予FULL Control。

我假设这是ASP.NET运行以访问注册表的用户。

然后我尝试禁用“包含此对象的父级的可inheritance权限”。

这也行不通。

在IIS管理器中,在我的应用程序的身份validation设置下,我将“匿名身份validation”用户设置为我自己的用户,该用户位于管理员组中。

似乎没什么用。

我该如何解决这个问题? 这是在我们的本地网络上运行的内部工具,因此我不太关心此阶段的安全权限。 我如何授予适当的权限?

谢谢!

在不知道您的Web应用程序试图完成什么的情况下很难进行故障排除。 但是,我认为这是一个基于Web的应用程序,这意味着您已经为您的Web创建了一个数据库。 首先,在您的Web.config’connectionString’中,尝试使用您用于登录SQL Server Management的用户名和密码。 不要使用Windows登录。 其次,尝试使用F5function键运行您的应用程序。 这将启动Visual Studio 2008附带的内置服务器。这不需要本地IIS。

如果仍然有问题,请发布或发送给我你的Web.config。 看看我能不能帮忙。

我必须为此应用程序将应用程序池标识设置为“LocalSystem”。 这使我的应用程序有足够的权限来读取注册表。