简体   繁体   English

MachineKey更改未反映在web.config中

[英]MachineKey change does not reflect in web.config

In my web application, there is an administrator ability to change the validation method/algorithm to SHA1 to HMACSHA256, HMACSHA384, etc. etc. 在我的Web应用程序中,管理员可以将验证方法/算法从SHA1更改为HMACSHA256,HMACSHA384等。

In the code, when I retrieve the value from the web.config using ConfigurationManager, it shows as being updated. 在代码中,当我使用ConfigurationManager从web.config中检索值时,它显示为已更新。

However, when I open up the Web.config itself, the value does not appear in the MachineKey section. 但是,当我打开Web.config本身时,该值不会出现在MachineKey部分中。 Why is it now showing up? 为什么现在显示?

edit: The technloogy I am using is Visual Studio C# and MVC. 编辑:我使用的技术是Visual Studio C#和MVC。 A portion of the web.config is below: 以下是web.config的一部分:

  <system.web>
<machineKey validationKey="22FEA7D6533FCCE331C2342A1801051F5E2890749CB2D5EF2EEABF8B0D944F389F46FA061D1A203EB75F3A9197914299676917FFD355456CFA0B49CA4C30B348"
  decryptionKey="30B2FA2A8C54665E18D9A35E3541BFED6A3E8A640DBA4070" />
<authentication mode="Forms">
  <forms name="FormsAuth1" loginUrl="https://localhost/OidcApplication/Oidc/Authenticate" timeout="2880" requireSSL="false" />
</authentication>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>

This is how I retrieve the machine key values: 这是我检索机器键值的方法:

machineKeyConfig = (MachineKeySection)GetConfigurationSection("system.web/machineKey");

And this is how I set the machine key values: 这就是我设置机器键值的方式:

var machineKeyConfig = (MachineKeySection)GetConfigurationSection("system.web/machineKey");

machineKeyConfig.DecryptionKey = machineKeySettings.DecryptionKey;
machineKeyConfig.Validation = machineKeySettings.Validation;
machineKeyConfig.ValidationKey = machineKeySettings.ValidationKey;
machineKeyConfig.CurrentConfiguration.Save(ConfigurationSaveMode.Minimal);

First of all, I would check whether the file you are saving to is the same you are reading: 首先,我将检查您要保存到的文件是否与读取的文件相同:

var ConfigFilePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

By the way, what's the class and namespace of the GetConfigurationSection method? 顺便说一句, GetConfigurationSection方法的类和名称空间是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM