我使用以下代码加密了web.config文件
protected void Page_Load(object sender, EventArgs e)
{
EncriptSection("connectionStrings", "DataProtectionConfigurationProvider");
}
private void EncriptSection(string sectionName, string provider)
{
Configuration config =
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection(sectionName);
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}
}加密web.config文件后,站点在本地系统中运行良好,但当我发布站点并部署到服务器时。
页面不读取web.config文件,给error.When我解密文件,然后将站点发布到服务器站点上运行良好。
如何加密文件并将其运行到服务器。
Below is the error which i am getting now :运行时错误
描述:服务器上发生应用程序错误。此应用程序的当前自定义错误设置防止远程查看应用程序错误的详细信息(出于安全原因)。但是,运行在本地服务器机器上的浏览器可以查看它。
详细信息:若要在远程计算机上查看此特定错误消息的详细信息,请在位于当前web应用程序根目录的web.config配置文件中创建一个web.config标记。然后,将这个<customErrors>标记的mode属性设置为Off。
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>注意:您看到的当前错误页可以通过修改应用程序的defaultRedirect配置标记的<customErrors>属性来指向自定义错误页面URL来替换为自定义错误页。
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>*之后我把**
<customErrors mode="Off"/> **出于信任,然后得到以下错误*
解析器错误消息:使用提供程序“DataProtectionConfigurationProvider”解密失败。来自提供程序的错误消息:无法在指定状态下使用的键。(HRESULT例外: 0x8009000B)
源错误:
Line 13: </system.web>
Line 14: <connectionStrings
configProtectionProvider="DataProtectionConfigurationProvider">
Line 15: <EncryptedData>
Line 16: <CipherData>
Line 17: <CipherValue>reertertertreterterterterterterterte
rtertertertertert5345345345 </CipherValue>源文件: C:\FOLDER\web.config行: 15
发布于 2015-01-08 06:57:26
您需要使用解密的web.config部分发布应用程序,因为用于加密/解密的密钥是特定于机器的。
要对web.config节进行在线加密,请在Application_Start() of global.asax中调用ProtectSection()方法。
因此,ProtectSection()方法将在应用程序第一次启动时执行此操作。
https://stackoverflow.com/questions/27834283
复制相似问题