问题描述
我正在尝试使用aspnet_regiis加密web.config文件中给出的连接字符串.所以我试图以aspnet_regiis.exe打开
I am trying to encrypt the connection string that is being given in the web.config file using aspnet_regiis.So I am trying to open the aspnet_regiis.exe as
aspnet_regiis -pe "connectionStrings" -app "/NewTestAPI" -prov "RsaProtectedConfigurationProvider"
或
aspnet_regiis -pe "connectionStrings" -app "/E:/Dropbox/NewTestAPI" -prov "RsaProtectedConfigurationProvider"
它引发错误,提示无法为所请求的配置对象创建配置文件.失败!"我什至尝试共享文件夹
It throws an error saying "Configruation file cannot be created for the requested Configuration object.Failed!" I tried even sharing the folder
aspnet_regiis -pe "connectionStrings" -app "/\\ABC\NewTestAPI" -prov "RsaProtectedConfigurationProvider"
即使抛出相同的错误,也无法为请求的Configuration对象创建配置文件.失败!"
Even that throws the same error Configruation file cannot be created for the requested Configuration object.Failed!"
下面是我拥有的connectionStrings
Below is the connectionStrings I have
<connectionStrings>
<add name="ProConnection" connectionString="Data Source=J;User Id=T;Password=C;pooling=true;min pool size=5;Max Pool Size=60" providerName="Oracle.DataAccess.Client"/>
</connectionStrings>
我还尝试给出了站点的物理路径以及站点ID,如图所示,但存在相同的错误
I also tried giving the physical path of the site and also the site ID which is as shown in the picture but same error
aspnet_regiis -pe"connectionStrings" -app"/E:\ Dropbox \ ABC \ TestAPI"-站点"3" -prov"RsaProtectedConfigurationProvider"
aspnet_regiis -pe "connectionStrings" -app "/E:\Dropbox\ABC\TestAPI" -site "3" -prov "RsaProtectedConfigurationProvider"
推荐答案
初始答案:
首先,您应确保通过以下方式授予对RSA加密密钥的访问权限:
First you should make sure you grant access to an RSA encryption key with:
.\aspnet_regiis.exe -pa "NetFrameworkConfigurationKey" "MySiteIdentity"
如果您不知道自己的网站身份是什么,则可以使用System.Security.Principal.WindowsIdentity.GetCurrent().Name
找到它.
If you don't know what your site identity is, you can find it using System.Security.Principal.WindowsIdentity.GetCurrent().Name
.
然后,如果web.config位于与DefaultWebsite不同的网站下,则可能需要指定-site
选项.如果未指定该选项,则默认为-site 1
(DefaultWebsite,其具有INSTANCE_ID服务器变量"1").为了找到您站点的INSTANCE_ID,您可以在.cshtml
页面中请求服务器变量,如下所示:
Then, if the web.config is under a different website than the DefaultWebsite, you'll probably need to specify the -site
option. If that option is not specified, it defaults to -site 1
(DefaultWebsite, which has the INSTANCE_ID server variable "1").In order to find your site's INSTANCE_ID you can request the server variables in a .cshtml
page like so:
@foreach (string var in Request.ServerVariables)
{
Response.Write(var + " " + Request[var] + "<br>");
}
现在,假设您发现站点的实例ID为2.您可以在命令中使用该实例ID,如下所示:
Now, suppose you find that your site's instance id is 2. You can use that in your command like this:
.\aspnet_regiis.exe -pe "connectionStrings" -app "/NewTestAPI" -site "2"
注意:"/NewTestAPI"路径是虚拟路径,并假定您的应用程序作为应用程序托管在本地IIS中.此外,仅当您的应用程序位于与DefaultWebSite不同的网站上,或者您再次删除并创建了DefaultWebsite时,才需要-site
选项.
Note: the "/NewTestAPI" path is a virtual path and assumes that your application is hosted in Local IIS as an application. Furthermore, the -site
option is only necessary if your app is under a different website than the DefaultWebSite, or if you removed and created the DefaultWebsite again.
更新:实际的问题是该应用程序是作为网站而不是应用程序托管在IIS中的(因此没有虚拟路径,只有物理路径).这就是为什么当尝试为aspnet_regiis提供虚拟路径(-app
选项)时会失败的原因.要为aspnet_regiis提供物理路径,我们必须使用-pef
选项,如下所示:
Update:The actual problem is that the app was hosted in IIS as a website, not an application (so no virtual path, only a physical one). That's why aspnet_regiis would fail when trying to give it a virtual path (the -app
option). To give aspnet_regiis a physical path we must use the -pef
option like so:
.\aspnet_regiis.exe -pef "connectionStrings" "E:\DropBox\ABC\TestApi"
这篇关于无法为请求的配置对象创建Web API配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!