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

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

问题描述

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



我想加密这个数据。我该怎么做?

 < connectionStrings> 
< add name =ISP_ConnectionStringconnectionString =Data Source = JIGAR;
初始目录= ISP;集成安全= True;
用户ID = jigar;密码= jigar123;
providerName =System.Data.SqlClient/>
< / connectionStrings>


解决方案

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

  C: \WINDOWS\Microsoft.Net\Framework(64)\(.Net version)\aspnet_regiis -peconnectionStrings

对于特定应用程序,您可以使用应用程序参数-app 应用程序名称,对于特定站点,您还可以使用站点参数-site 站点ID



有关详细信息,请参阅 http://msdn.microsoft.com/en-us/library/dtkwfdky.aspx



请注意,这适用于网络应用程序阳光,而不是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天全站免登陆