views:

711

answers:

4

I cant figure out how to use 'Profile.GetProfile()' method in a library class. I tried using this method in a Page.aspx.cs and it worked perfectly.

How can I make a method that works in the page.aspx.cs, work in the class library.

A: 

Have you tried adding reference to System.Web.dll to your class library and then:

if (HttpContext.Current == null) 
{
    throw new Exception("HttpContext was not defined");
}
var profile = HttpContext.Current.Profile;
// Do something with the profile
Darin Dimitrov
HttpContext.Current.Profile only have method regarding the current profile, and does not contain GetProfile() Method
Or Betzalel
If I tried HttpContext.Current.Profile I obviously Added the system.web Dll to my class library its the same as HttpContext.Current.Profile
Or Betzalel
Could you point to the MSDN documenattion of the GetProfile method you are talking about? I can't seem to find such method.
Darin Dimitrov
Profile.GetProfile(string username) ill give you an MSDN documenattion in a few minutes
Or Betzalel
System.Web.UI.Page or its base classes does not contain a property called "Profile".
Darin Dimitrov
The object returned by HttpContext.Current.Profile is a dynamically generated ProfileCommon object. It does have a GetProfile() method, but it doesnt show up in intellisense due to being dynamically generated ...
codeulike
+2  A: 

In ASP.NET, Profile is a hook into the HttpContext.Current.Profile property, which returns a dynamically generated object of type ProfileCommon, derived from System.Web.Profile.ProfileBase.

ProfileCommon apparently includes a GetProfile(string username) method, but you wont find it documented officially in MSDN (and it wont show up in intellisense in visual studio) because most of the ProfileCommon class is dynamically generated when your ASP.NET application is compiled (The exact list of properties and methods will depend on how 'profiles' are configured in your web.config). GetProfile() does get a mention on this MSDN page, so it seems to be real.

Perhaps in your library class, the problem is that the configuration info from web.config is not being picked up. Is your library class part of a Solultion that includes a Web Application, or are you just working on the library in isolation?

codeulike
The library is a part of the solution
Or Betzalel
In your library class, do other properties of the 'Profile' object work OK, or is the whole Profile object not working?
codeulike
A: 

Ran into the same problem today. I need access the profile information within the context of a SharePoint alert notification handler (IAlertNotifyHandler). My UserProfile object return null due to the missing HTTPContext. What is your get-around solution for this? Thanks.

David