C# 在web.config中设置machineKey未按预期运行
我有一个问题(或者至少我认为我有)。我试图在网站的web.config中设置网站的机器密钥,以便为将来在网站之间共享表单身份验证数据做好准备。我首先在web.config中设置以下内容:C# 在web.config中设置machineKey未按预期运行,c#,asp.net,web-config,C#,Asp.net,Web Config,我有一个问题(或者至少我认为我有)。我试图在网站的web.config中设置网站的机器密钥,以便为将来在网站之间共享表单身份验证数据做好准备。我首先在web.config中设置以下内容: <machineKey validationKey="<SOME_VALUE>" decryptionKey="<SOME_VALUE>" validation="SHA1" decryption="AES"/> var machineConfigMachineKey
<machineKey validationKey="<SOME_VALUE>" decryptionKey="<SOME_VALUE>" validation="SHA1" decryption="AES"/>
var machineConfigMachineKey = (MachineKeySection)WebConfigurationManager.OpenMachineConfiguration().SectionGroups["system.web"].Sections["machineKey"];
var webConfigMachineKey = (MachineKeySection)WebConfigurationManager.OpenWebConfiguration("").SectionGroups["system.web"].Sections["machineKey"];
Response.Write("<pre>");
Response.Write("<b>machine.config decrypt: </b>" + machineConfigMachineKey.DecryptionKey + "<br />");
Response.Write("<b>web.config decrypt: </b>" + webConfigMachineKey.DecryptionKey + "<br />");
Response.Write("<br />");
Response.Write("<b>machine.config validate: </b>" + machineConfigMachineKey.ValidationKey + "<br />");
Response.Write("<b>web.config validate: </b>" + webConfigMachineKey.ValidationKey + "<br />");
Response.Write("</pre>");
Response.End();
显然,我对此感到非常困惑,因为我希望在web.config中看到来自新machineKey元素的自定义值,而不是“自动生成、隔离应用程序”
我是否遗漏了一些对我来说显而易见的东西
谢谢:)改用静态API
WebConfiguration Manager.GetSection(“system.web/machineKey”)
。它自动执行遍历配置层次结构的逻辑,找到最适用的层次结构(通常为当前应用程序~/Web.config),并提取其特定值。Sweet!下周我返回此项目时将进行回顾:)
machine.config decrypt: AutoGenerate,IsolateApps
web.config decrypt: AutoGenerate,IsolateApps
machine.config validate: AutoGenerate,IsolateApps
web.config validate: AutoGenerate,IsolateApps