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

发布于 2024-08-08 02:10:06 字数 452 浏览 3 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦亦如幻 2024-08-15 02:10:06

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

我个人没有使用过上面的程序集,所以其他人可能会就此提供一些建议。
但是,您也可以尝试:

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

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

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:

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

You won't get intellisense with this method, but as long as you know the property name, it can be accessed like that.

唐婉 2024-08-15 02:10:06

在 web.config 文件中指定属性,如下所示:-
ProfilePropertyWeb.config

现在,编写以下代码: -

Code Behind Profile Properties

编译并运行代码。您将得到以下输出: -

Output

Specify properties in web.config file as follows : -
ProfilePropertyWeb.config

Now, write the following code : -

Code Behind Profile Properties

Compile and run the code. You will get following output: -

Output

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文