Following on from my last post I've since discovered how to access the User's Profile in an external Class Library (like I've mentioned before I prefer to factor out all business logic code into a separate class library).

Anyway the code is almost the same, although unfortunately you don't get strongly typed properties out of the box (unless you create your own profile object, inheriting from System.Web.Profile.ProfileBase).

Here's how to access the current user's properties (using FirstName/LastName) as before, only this time in a separate dll...

string firstname = HttpContext.Current.Profile["FirstName"];
string lastName = HttpContext.Current.Profile["LastName"];

And as before it's also possible to access other user's profiles (where 'Brad' is the user's username):

ProfileBase profileBase = ProfileBase.Create("Brad", true);
string firstname = profileBase["FirstName"];
string lastname = profileBase["LastName"];

Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Monday, February 04, 2008 4:11 PM |

Comments

Gravatar
# re: ASP.NET: Accessing User Profiles in external Class Library (Dll)
Posted by Helen
on 6/9/2008 2:15 PM
Thanks, this was exactly what I needed!

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 8 and 6 and type the answer here: