關(guān)于.net2.0中Webconfig中連接串的加密
2006/12/26 17:46:52

    ASP.NET 2.0 現(xiàn)在允許您對配置文件的單個節(jié)進行加密,這樣,幾乎不可能使用文本編輯器來讀取這些配置節(jié)。
 
 
 
 
 
 
 
 
 
 
 
 
 
 


ASP.NET 包括兩個內(nèi)置的受保護配置提供程序:RSA 和 DPAPI DPAPI 提供程序使用特定于計算機的密鑰,因此您必須在每臺計算機上實際加密配置設(shè)置。默認使用的 RSA 提供程序允許您選擇創(chuàng)建 RSA 密鑰并將其安裝在其他計算機上,這樣您就可以在這些計算機之間復(fù)制相同的配置文件。此外,您還可以安裝其他受保護配置提供程序供系統(tǒng)使用。

調(diào)用配置管理 API 可透明地使用加密的節(jié),因為該 API 自動處理加密和解密。若要通過編程方式將配置節(jié)設(shè)置為加密的,可獲取 ConfigurationSection.SectionInformation 屬性,然后傳入您選擇的保護提供程序調(diào)用 ProtectSection 方法。若要使用默認提供程序,可以傳入 null 或空字符串。UnprotectSection 方法禁用配置節(jié)的加密。

下面的示例演示如何以編程方式對配置節(jié)進行加密,配置 API 如何自動處理加密的節(jié)。


  <%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Xml" %>

  <script runat="server" language="C#">
   
    public void Page_Load(object source, EventArgs e)
    ...{
        if (!IsPostBack) ...{
            UpdateUI();
        }
    }

    void ProtectButton_OnClick(Object source, EventArgs e)
    ...{
        String path = Request.CurrentExecutionFilePath;
        path = path.Substring(0, path.LastIndexOf('/'));

        // Get configuration.
        Configuration config = WebConfigurationManager.OpenWebConfiguration(path);
        ConfigurationSection appSettings = config.GetSection("appSettings");
        if (appSettings.SectionInformation.IsProtected)
        ...{
            appSettings.SectionInformation.UnprotectSection();
        }
        else
        ...{
            appSettings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
        }

        try
        ...{
          config.Save();
          UpdateUI();
        }
        catch (Exception ex)
        ...{
          Response.Write("In order to modify configuration settings, the ASP.NET process account (either the local ASPNET or Network Service account, by default) ");
          Response.Write("must have write permission granted for the Web.config file in the sample directory");
        }
    }

    void UpdateUI()
    ...{
        String path = Request.CurrentExecutionFilePath;
        path = path.Substring(0, path.LastIndexOf('/'));

        // Get configuration.
        Configuration config = WebConfigurationManager.OpenWebConfiguration(path);

        // Show XML for app settings.
        ConfigurationSection appSettings = config.GetSection("appSettings");

        // Set protect button appropriately.
        if (appSettings.SectionInformation.IsProtected)
        ...{
            Encrypted.Text = "Yes";
            ProtectButton.Text = "Unprotect";
        }
        else
        ...{
            Encrypted.Text = "No";
            ProtectButton.Text = "Protect";
        }

        // Show XML for app settings.
        AppSe

下一頁
返回列表
返回首頁 主站蜘蛛池模板: 久久久久久亚洲av无码蜜芽| 成人免费福利视频| 又黄又爽又色又刺激的视频| 2020欧美极品hd18| 在线91精品亚洲网站精品成人| 中文字幕av一区乱码| 日韩视频免费看| 免费国产污网站在线观看| 色妞妞www精品视频| 国产精品免费看| h无遮挡男女激烈动态图| 无码国内精品人妻少妇蜜桃视频| 亚洲免费人成在线视频观看| 精品国产乱码久久久久久浪潮 | 国产自产2023最新麻豆| 久久久久久不卡| 最近更新的2019免费国语电影 | 久久99热精品这里久久精品| 欧美三日本三级少妇三级久久| 免费在线看片网站| 老师别揉我胸啊嗯上课呢视频| 国产在线无码视频一区二区三区| 99热99re| 日本高清va不卡视频在线观看| 亚洲国产精久久久久久久| 浮力国产第一页| 免费大片av手机看片| 老色鬼久久综合第一| 国产内射爽爽大片视频社区在线| 免费看黄的网页| 国产精品无码素人福利免费| 91香蕉国产线观看免费全集| 在线观看网址入口2020国产| yy111111影院理论大片| 成人乱码一区二区三区AV| 中文字幕日韩精品在线| 日本丰满熟妇BBXBBXHD| 亚洲AV色香蕉一区二区三区蜜桃 | 风间由美性色一区二区三区| 岳又湿又紧粗又长进去好舒服| 中文字幕一区二区区免|