Web.config文件进行加密和安装 [英] Encrypting Web.config and installing

查看:347
本文介绍了Web.config文件进行加密和安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的加密过程,并企图未能成功安装一个加密的web.config文件到一个托管公司服务器。我使用微软的Visual Web Developer 2010防爆preSS。

I am new to the encryption process and have tried unsuccessfully to install an encrypted web.config file onto a hosting companies server. I am using Microsoft Visual Web Developer 2010 Express.

我跟了位于演练的步骤:加密配置信息使用保护几次

请注意关于演练中,我没有在我的web.config文件中的任何MachineKeys的,所以我跳过的加密步骤。

Please Note regarding the walkthrough, I do not have any machineKeys in my web.config file, so I skipped that encryption step.

当我跑为aspnet_regiis -pef是connectionStringsC:\\用户...... \\ mywebsite.com结果
回报是:
加密配置节...
成功了!

When I Ran the aspnet_regiis -pef connectionStrings "c:\Users......\mywebsite.com"
Return is: Encrypting configuration section ... Succeeded!

2)然后我FTP我的web.config文件,该网站得到下面的错误:注:8号线高亮显示)

2) I then FTP my web.config file and the site gets the below error: Note: The Line 8 is highlighted)

配置错误
说明:该请求提供服务所需的配置文件的处理过程中发生错误。请检查下面的特定错误详细信息并适当地修改配置文件。

Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

分析器错误信息:无法使用提供解密RsaProtectedConfigurationProvider。从提供的错误信息:坏数据

Parser Error Message: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Bad Data.

源错误:

6号线:
7号线:
8号线:
10号线:

Line 6: Line 7: Line 8: Line 10:

源文件:C:\\ HostingSpaces * **用户名* mywebsite.com \\ wwwroot的\\ web.config行:8

Source File: C:\HostingSpaces*username**mywebsite.com*\wwwroot\web.config Line: 8

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.1

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

我知道一定是有一块缺失,但我已经搜查,没有发现任何东西。我给托管公司,以了解他们是否需要做关于加密网站任何东西,他们还没有作出回应。

I know there must be some piece missing but I have searched and have not found anything. I emailed the hosting company to find out if they need to do anything regarding encrypting web sites and they have not responded yet.

我期望的是,有位于别处的一个关键这需要对加密值并使用algorhythm解密。如果是这样的话,在那里我会拿到钥匙,并在那里将它去吧。

What I would expect is that there is a key that resides elsewhere which takes the encrypted value and decrypts it using an algorhythm. If this is so, where would I get that key and where would it go.

任何帮助是极大AP preciated和有些诧异我找不到类似这样在网络上的任何问题。

Any help is greatly appreciated and somewhat surprised I cannot find any issues similar to this on the web.

谢谢了。

推荐答案

强尼Ø - 谢谢。这个工作这么容易。 CP

Jonny O - Thanks. This worked so easily. CP

我添加Global.asax文件和这里的code片段,走进了这个文件(的global.asax.cs)。

I added the global.asax file and here are the code snippets that went into this file (global.asax.cs).

当然这在很大程度上是从上面复制的,但它是我的整个解决方案。再次感谢。

Granted much of this is duplicated from above, but it is my entire solution. Thanks again.

using System.Web.Configuration;
using System.Configuration;
using System.Web.Hosting;

    protected void Application_Start(object sender, EventArgs e)
    {
        //Test to see if this app is being started on the development machine (e.g. in the debugger)
        //This code will encript web.config the first time this program runs.
        //Therefore, it is important to have a backup copy of the non-encrypted web.config as this
        //code below will encrypt it, which is what we want to happen on the production server.            
        if (! System.Diagnostics.Debugger.IsAttached )
        {
            EncryptConfig();  //See below
        }
    }



    /// <summary>
    /// This technique of encrypting the web.config file was learned from this forum post:
    /// http://stackoverflow.com/questions/5602630/encrypting-web-config-and-installing
    /// </summary>
    private static void EncryptConfig()
    {
        System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath);

        foreach (string sectionName in new[] { "connectionStrings", "appSettings" })
        {
            ConfigurationSection section = config.GetSection(sectionName);
            if (!section.SectionInformation.IsProtected)
            {
                section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
            }
        }

        config.Save();
    }

这篇关于Web.config文件进行加密和安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆