Web.config加密错误

时间:2010-01-05 17:13:22

标签: asp.net encryption rsacryptoserviceprovider aspnet-regiis.exe

遇到加密问题。我向RSA文件夹的所有用户授予了完全权限。我做了

C:\>aspnet_regiis -pe "appSettings" -location "web.config" -prov "RsaProtectedCo
nfigurationProvider"
Encrypting configuration section...
An error occurred executing the configuration section handler for appSettings.

Failed to encrypt the section 'appSettings' using provider 'RsaProtectedConfigur
ationProvider'. Error message from the provider: Object already exists.

Failed!

然后我做了

C:\>aspnet_regiis -pa "NetFrameworkConfigurationKey" "administrator"
Adding ACL for access to the RSA Key container...
The RSA key container was not found.
Failed!

其次是

C:\>aspnet_regiis -pc "NetFrameworkConfigurationKey" -exp
Creating RSA Key container...
The RSA key container could not be opened.
Failed!

没有什么对我有用。

有人可以帮忙吗?

由于

4 个答案:

答案 0 :(得分:9)

我遇到了同样的失败问题:

  

aspnet_regiis -pa“NetFrameworkConfigurationKey”“{Domain} {Username}”

以上行返回“未找到RSA密钥容器。”

要解决此问题,我必须以管理员身份运行命令提示符(打开开始>附件>然后右键单击命令提示符并选择以管理员身份运行...)。即使我的帐户是管理员帐户,我也必须这样做。

答案 1 :(得分:1)

C:\>aspnet_regiis -pe "appSettings" -location "web.config"
       -prov "RsaProtectedConfigurationProvider"

在此行中您的位置不正确。当您使用-pd时,交换机位置基于IIS的应用程序路径,并且web.config被假定为加密点。

因此,例如,如果您在IIS中有一个名为“Website 1”的应用程序和另一个名为“Website 2”的应用程序,并且您希望加密“Website 1”中的web.config,则可以使用以下行:

C:\>aspnet_regiis -pe "appSettings" -location "Website 1"
        -prov "RsaProtectedConfigurationProvider"

就个人而言,我发现使用-pef开关更容易,因为我可以直接指向Web应用程序的物理目录。

关注Encrypting Configuration Information Using Protected Configuration 上的MSDN教程。我已多次使用它并且还没有问题做过加密。

答案 2 :(得分:1)

您需要将“管理员”更改为运行ASP.NET服务的帐户。因为,您可能没有将ASP.NET作为管理员服务帐户运行。如果你是,那么你应该重新考虑你的决定。

例如,这是我使用的:

 aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT Authority\Network Service"

aspnet_regiis -pa "NetFrameworkConfigurationKey" "ASPNET"

然后加密,我使用:

  aspnet_regiis -pef "connectionStrings"

 aspnet_regiis -pef "appSettings"

答案 3 :(得分:0)

我必须找到安装证书的文件夹,并在上述命令出错之前取消所有权/授予权限。错误说无法找到密钥容器,但实际上我只是没有证书的权限。在我的情况下,我从其他人那里继承了一台开发机器,在我运行必要的命令之前需要给自己一些权限。

我曾希望通过证书文件夹位置,详细步骤等提供更详细的回复,但没有时间,只是想记下我在我的场景中必须做的事情。