ASP.NET: Accessing User Profiles in external Class Library (Dll)

by Brad 4. February 2008 16:11

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"];

Tags:

Comments

6/9/2008 1:15:39 PM #

Thanks, this was exactly what I needed!

Helen |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar