gpt4 book ai didi

c# - 在 web 配置中动态添加值?如何+最佳方式

转载 作者:太空狗 更新时间:2023-10-30 00:16:47 25 4
gpt4 key购买 nike

我刚刚想出了在 asp.net 的 web.Config 中动态读取、写入和添加值。有很多想法,但我只是想知道在 Web 配置中动态添加值的最佳方式是什么。

例如在我的例子中我必须添加

 <identity  userName="someDomain\User" password="password" impersonate="true" />

从代码隐藏在网络配置中标记。

等待好的回应

最佳答案

我找到你了,你想要的代码是:

 public void saveIdentity(string username, string password, bool impersonate)
{
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
IdentitySection identitySection = (IdentitySection)objConfig.GetSection("system.web/identity");
if (identitySection != null)
{
identitySection.UserName = username;
identitySection.Password = password;
identitySection.Impersonate = impersonate;
}
objConfig.Save();
}

关于c# - 在 web 配置中动态添加值?如何+最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5324924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com