加密在C#中的web.config文件中的连接字符串 [英] Encrypting the connection string in web.config file in C#

查看:456
本文介绍了加密在C#中的web.config文件中的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的web.config 文件写入我的数据库,用户名和密码的名称作为连接字符串。

我想这个数据进行加密。我该怎么办呢?

 <的ConnectionStrings>
  <添加名称=ISP_ConnectionString的connectionString =数据源= JIGAR;
             初始目录= ISP;集成安全性= TRUE;
             用户ID = jigar;密码= jigar123;
             的providerName =System.Data.SqlClient的/>
< /的ConnectionStrings>
 

解决方案

您可以只使用apnet_regiis工具来做到这一点,只是做

  C:\ WINDOWS \ Microsoft.Net \框架(64)\(.NET版本)\为aspnet_regiis -pe的ConnectionStrings
 

针对特定的应用程序,你可以使用应用程序参数-app的应用程序名的,而对于一个特定的网站,你也可以使用该网站的说法上门的网站ID

有关详细信息请参阅<一href="http://msdn.microsoft.com/en-us/library/dtkwfdky.aspx">http://msdn.microsoft.com/en-us/library/dtkwfdky.aspx.

请注意,这适用于只,而不是一个Web应用程序的Windows应用程序。

另外请注意,您必须在命令提示符下使用提升的权限(以管理员身份运行)。

运行

I have written the name of my database, username and password in my web.config file as connection string.

I want to encrypt this data. How can I do it?

<connectionStrings>
  <add name="ISP_ConnectionString" connectionString="Data Source=JIGAR;
             Initial Catalog=ISP;Integrated Security=True;
             User ID=jigar;Password=jigar123;
             providerName="System.Data.SqlClient" />
</connectionStrings>

解决方案

You can just use the apnet_regiis tool to do that ,just do

C:\WINDOWS\Microsoft.Net\Framework(64)\(.Net version)\aspnet_regiis -pe "connectionStrings" 

for a specific application you can use the app argument -app application name, and for a specific site you can also use the site argument "-site site id".

For more details see http://msdn.microsoft.com/en-us/library/dtkwfdky.aspx.

Note that this works for a web application only and not for a windows application.

Also note that you have to run it from a command prompt with elevated privileges ("run as administrator").

这篇关于加密在C#中的web.config文件中的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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