3

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.

Xaisoft
  • 44,403
  • 86
  • 275
  • 425

2 Answers2

3

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.

keyboardP
  • 67,723
  • 13
  • 149
  • 201
  • Instead of inheriting ProfileBase and creating own class, I guess the method you had provided is the simplest way. You additionally set the value of the property using - HttpContext.Current.Profile.SetPropertyValue("CustomerName", "MyCustomer") – Anil Purswani Aug 08 '12 at 08:36
0

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

Anil Purswani
  • 1,807
  • 6
  • 31
  • 63