C# 用于 ASP.NET 中的 MachineKey

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/550210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 07:48:06  来源:igfitidea点击:

Uses for MachineKey in ASP.NET

c#asp.netcookiesviewstatemachinekey

提问by BenMaddox

What different ways are Machine Keys useful in asp.net? I think the following are correct but thought there may be more.

机器密钥在 asp.net 中有哪些不同的用途?我认为以下是正确的,但认为可能还有更多。

  1. Multiple applications can use the same cookie
  2. Multiple servers can work with the same viewstate
  1. 多个应用程序可以使用同一个 cookie
  2. 多个服务器可以使用相同的视图状态

采纳答案by Sergiu Damian

MachineKey is used for:

MachineKey 用于:

  • ViewState encryption and validation
  • Forms Authentication (or Federated Authentication) uses this key for signing the authentication ticket
  • ViewState 加密和验证
  • 表单身份验证(或联合身份验证)使用此密钥对身份验证票进行签名

Having a Web App installed on multiple servers requires same Machine Key configured on all of them in order for Load Balancing to work.

在多个服务器上安装 Web 应用程序需要在所有服务器上配置相同的机器密钥,以便负载平衡工作。

To see all details, please refer to: MSDN How To: Configure MachineKey in ASP.NET 2.0

要查看所有详细信息,请参阅:MSDN How To: Configure MachineKey in ASP.NET 2.0

回答by vajarov

Encryption - very common.

加密 - 很常见。

回答by eglasius

Machine key is also used to encrypt/decrypt the webresources.axd parameters.

机器密钥还用于加密/解密 webresources.axd 参数。

Even on a single server the machine key should be configured, because any recycle of the app domain will generate a new key when it is set to auto. This causes the next postback just for pages rendered before the recycle, to cause a viewstate validation error, and also issues with the resources during that time.

即使在单个服务器上,也应该配置机器密钥,因为当应用域设置为自动时,任何应用程序域的回收都会生成一个新密钥。这会导致仅针对在回收之前呈现的页面进行下一次回发,从而导致视图状态验证错误,并且在此期间还会出现资源问题。