用 C# 加密 web.config 文件中的连接字符串 [英] Encrypting the connection string in web.config file in C#
问题描述
我已经在我的 web.config
文件中写入了我的数据库名称、用户名和密码作为连接字符串.
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>
推荐答案
你可以使用 apnet_regiis 工具来做到这一点,就去做
You can just use the apnet_regiis tool to do that ,just do
C:WINDOWSMicrosoft.NetFramework(64)(.Net version)aspnet_regiis -pe "connectionStrings"
对于特定应用程序,您可以使用 app 参数 -app application name,对于特定站点,您还可以使用站点参数-site site id".
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".
有关详细信息,请参阅 http://msdn.microsoft.com/en-我们/图书馆/dtkwfdky.aspx.
For more details see http://msdn.microsoft.com/en-us/library/dtkwfdky.aspx.
请注意,这仅适用于 Web 应用程序,不适用于 Windows 应用程序.
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屋!