Monday, February 26, 2007

How To: Read Profile outside of ASP.NET

first of all thanks to daniel larson with his blog entry :-)

in case you're using your own classes and not just properties then here a small overview what you need to do:


namespace YourNameSpace.Profile.Extension
{
///


/// UserAddress contains the users address information,
/// this class is used in the profile .net 2.0 approach
///

[Serializable]
public class UserAddress
{
public UserAddress() { }

#region Property: Street
private string street;

///
/// Gets/sets the Street
///

public string Street
{
[System.Diagnostics.DebuggerStepThrough]
get { return this.street; }

[System.Diagnostics.DebuggerStepThrough]
set { this.street = value; }
}
#endregion


... all you other stuff ....

the web.config looks like this:


<profile>
<properties>
<add name="UserAddress" type="YourNameSpace.Profile.Extension.UserAddress" serializeAs="Xml"/>

and finally in your code you run the following code lines:

ProfileBase profile = ProfileBase.Create(data.Login);

string street = (profile.GetPropertyValue("UserAddress") as Profile.UserAddress).Street;

No comments:

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge