【问题标题】:MachineKey change does not reflect in web.configMachineKey 更改未反映在 web.config 中
【发布时间】:2018-08-11 18:15:57
【问题描述】:

在我的 Web 应用程序中,管理员可以将验证方法/算法更改为 SHA1 到 HMACSHA256、HMACSHA384 等。

在代码中,当我使用 ConfigurationManager 从 web.config 检索值时,它显示为正在更新。

但是,当我打开 Web.config 本身时,该值不会出现在 MachineKey 部分中。为什么现在出现了?

edit:我使用的技术是 Visual Studio C# 和 MVC。 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>

这就是我检索机器键值的方式:

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

这就是我设置机器键值的方式:

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

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

【问题讨论】:

  • 您使用的是哪种技术?网络表格? MVC?你能分享你的网络配置,或者你的解决方案资源管理器窗口的图片吗?
  • Francesco,请参阅我对上述帖子的最新编辑。谢谢!
  • 好的,能否请您发布用于从 web.config 检索值的代码?另外,您的解决方案中有多少个 web.config(例如,一个用于调试,另一个用于生产等)?
  • 当然,弗朗西斯科...
  • Francesco,我已经添加了如何获取和设置机器密钥的代码部分。

标签: c# web-config forms-authentication configurationmanager machinekey


【解决方案1】:

首先,我会检查您保存到的文件是否与您正在阅读的文件相同:

var ConfigFilePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

顺便问一下,GetConfigurationSection方法的类和命名空间是什么?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-12
    • 2015-03-06
    • 1970-01-01
    • 2023-02-10
    • 2018-04-14
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多