无法从 web.config 访问自定义配置文件属性?
我的 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。配置文件也不会显示在智能感知中。
I have the following two profile properties in my web.config file between the System.Web tags:
<anonymousIdentification enabled="true"/>
<profile>
<properties>
<add name="CustomerName" allowAnonymous="true"/>
<add name="CustomerID" allowAnonymous="true"/>
</properties>
</profile>
When I try to access the Profile.CustomerName or Profile.CustomerID from an aspx.cs file, it doesn't show up. I thought when you create a custom profile property, it automatically updates the aspnetdb with the new properties. Profile doesn't show up in intellisense as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在创建 Web 应用程序,则会出现此问题。与网站不同,Web 应用程序不会生成 ProfileCommon 类。
您可以按照以下方法:
http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx
(附录2)
我个人没有使用过上面的程序集,所以其他人可能会就此提供一些建议。
但是,您也可以尝试:
使用此方法不会获得智能感知,但只要您知道属性名称,就可以这样访问它。
This problem occurs if you are creating a Web Application. Web Apps, unlike Websites, don't generate the ProfileCommon class.
You could either follow this method:
http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx
(Appendix 2)
I haven't personally used the above assembly, so someone else might give some advice on that.
However, you could also try:
You won't get intellisense with this method, but as long as you know the property name, it can be accessed like that.
在 web.config 文件中指定属性,如下所示:-
现在,编写以下代码: -
编译并运行代码。您将得到以下输出: -
Specify properties in web.config file as follows : -
Now, write the following code : -
Compile and run the code. You will get following output: -