gpt4 book ai didi

c# - 无法从 web.config 访问自定义配置文件属性?

转载 作者:行者123 更新时间:2023-11-30 16:35:41 25 4
gpt4 key购买 nike

我的 web.config 文件中的 System.Web 标记之间有以下两个配置文件属性:

<anonymousIdentification enabled="true"/>
<profile>
<properties>
<add name="CustomerName" allowAnonymous="true"/>
<add name="CustomerID" allowAnonymous="true"/>
</properties>
</profile>

当我尝试从 aspx.cs 文件访问 Profile.CustomerName 或 Profile.CustomerID 时,它没有显示。我认为当您创建自定义配置文件属性时,它会自动使用新属性更新 aspnetdb。配置文件也不会显示在智能感知中。

最佳答案

如果您正在创建 Web 应用程序,则会出现此问题。与网站不同,Web 应用程序不会生成 ProfileCommon 类。您可以遵循以下方法: http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx(附录二)

我没有亲自使用过上面的程序集,所以其他人可能会给出一些建议。但是,您也可以尝试:

Object customerName = HttpContext.Current.Profile.GetPropertyValue("CustomerName") 

使用此方法您不会获得智能感知,但只要您知道属性名称,就可以像这样访问它。

关于c# - 无法从 web.config 访问自定义配置文件属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1592140/

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