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

<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
(附录2)

我没有亲自使用以上程序集,因此其他人可能会对此提供一些建议。
但是,您也可以尝试:

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


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

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

10-12 00:29
查看更多