Asp.net在sessionState中加密sqlConnectionString

发布于 2024-12-09 22:27:43 字数 83 浏览 0 评论 0原文

我在我的应用程序中使用 sessionState mode = "SQLServer"。有什么方法可以加密 web.config 中传递的连接字符串吗?

I am using sessionState mode = "SQLServer" in my application. Is there any way to encrypt the connection string that was passed in web.config?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偷得浮生 2024-12-16 22:27:43

要加密应用程序之间的 SQL Server 连接,您只需添加

encrypt=true

到连接字符串,例如:

"Server=##.##.##.##,1092;Database=dbname;uid=username;pwd=password;encrypt=true"

要加密 web.config 中的字符串,请参阅 如何加密连接字符串-in-web.config

To encrypt sql server connection between applications you can just add

encrypt=true

to the connection string, eg:

"Server=##.##.##.##,1092;Database=dbname;uid=username;pwd=password;encrypt=true"

To encrypt the string in web.config see how-to-encrypt-connection-string-in-web.config

人│生佛魔见 2024-12-16 22:27:43

我也处于同样的境地,也找不到任何答案。接受的答案也没有回应我认为提出的问题。经过一番研究,我执行了以下操作来解决该问题,并加密了具有 web.config 的 connectionStringsessionState 节点

加密:

您可以按照按照以下步骤加密 web.config 的特定部分:

  • 以管理员身份运行命令提示符

  • 执行命令:

    <预置><代码> cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

  • 执行命令:

ASPNET_REGIIS -pef "system.web/sessionState" "PhysicalPathOfWebsiteThatHasWebConfigFile"

解密:

同样,如果要解密 web.config 中的特定节点,请按照与上述步骤相同,并在最后一步中将 -pef 替换为 -pdf,该实用程序将解密特定节点

上述说明命令:

  1. ASPNET_REGIIS:取自官方MSDN,您可以使用 ASP.NET IIS 注册工具 (Aspnet_regiis.exe) 来加密或解密网页配置文件。处理 Web.config 文件时,ASP.NET 将自动解密加密的配置元素。 -pef 告诉您想要使用它来加密 web.config 中的特定部分。它还有其他用途,并在官方 MSDN

  2. system.web/sessionState 是您想要的特定节点加密。

  3. PhysicalPathOfWebsiteThatHasWebConfigFile 是应用程序的物理路径(web.config 所在的位置)。请不要在路径末尾添加额外的“\”。

其他参考链接:

https://learn.microsoft.com/en-us/previous-versions/aspnet/zhhddkxy(v=vs.100)

aspnet_regiis.exe 做什么

I was in the same position and I also couldn't find any answer. The accepted answer also doesnt reciprocate the question asked in my opinion. After some research, i did the following to solve the issue and encrypted the sessionState node having connectionString of web.config

Encryption:

You can follow the following steps to encrypt a specific section of web.config:

  • Run command prompt as an administrator

  • Execute the command:

     cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
    
  • Execute the command:

ASPNET_REGIIS -pef "system.web/sessionState" "PhysicalPathOfWebsiteThatHasWebConfigFile"

Decryption:

Similarly if you want to decrypt a specific node in the web.config, follow the same above steps and replace -pef with -pdf in the final step and the utility will decrypt the specific node

Explanation about above commands:

  1. ASPNET_REGIIS: Taken from official MSDN, You can use the ASP.NET IIS Registration Tool (Aspnet_regiis.exe) to encrypt or decrypt sections of a Web configuration file. ASP.NET will automatically decrypt encrypted configuration elements when the Web.config file is processed. And -pef tells that you want to use it for encrypting a specific section in your web.config. It serves other purposes as well as explained in the official MSDN

  2. system.web/sessionState is the specific node that you want to encrypt.

  3. PhysicalPathOfWebsiteThatHasWebConfigFile is the physical path of your application (where web.config is located). Please do not add an extra ‘\’ at the end of the path.

Other Reference Links:

https://learn.microsoft.com/en-us/previous-versions/aspnet/zhhddkxy(v=vs.100)

What does aspnet_regiis.exe do

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文