Hello Eric,
Based on my understanding, you have an ASP.NET 2.0 web application which
use the profile service to store some custom properties for membership
users. Also, you has another offline application that will need to read the
profile datas (properties for users in that application), but met some
problems,correct?
As for the offline application , is it also an ASP.NET application and
configure to use the same profile datasource provider or is it a
winform/console application?
Regarding on the three questions you mentioned, here are my suggestions:
1) What's the proper way to read a user's profile from an offline
application/class library. I am currently using
System.Web.Profile.ProfileBase.Create(username, true). I'll be looping
through profiles in a batch job.
======================================
If your offline appliation is also an ASP.NET application which has
configured to use the same profile provider and database as your main
application. You can simply use the following code to loop all the users'
profiles and properties:
<<<<<<<<<<<<<<<<<<<<
public partial class ProfilePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DumpProfile();
}
protected void DumpProfile()
{
//I didn't involve anonymous records
ProfileInfoCollection pis =
ProfileManager.GetAllProfiles(ProfileAuthenticatio nOption.Authenticated);
foreach (ProfileInfo pi in pis)
{
ProfileBase pb = ProfileBase.Create(pi.UserName);
Response.Write("<br/>user: " + pb.UserName);
foreach (SettingsProperty sp in ProfileBase.Properties)
{
Response.Write("<br/>" + sp.Name + ": " +
pb.GetPropertyValue(sp.Name));
}
}
}
}
>>>>>>>>>>>>>>>>>>>>
2) Why is my offline app not showing all of the profile properties (but is
showing some of them? I have the same entries in my app.config file as on
my
website. (yes even made sure that they are under <system.web>)
===============================
As you mentioned App.config, is the offline application an non-ASP.NET one?
As far as I know, for two ASP.NET application, as long as they use the same
profile database setting (in provider) they can share the profile datas. I
haven't tried a non-ASP.NET context, I'll perform some research on this,
however, this case(read profile in non-ASP.NET context) is not originally
designed for.
3) In my website, why are my custom property values sometimes empty? If I
need to "get profile for user X" even if user x isn't the current user,
what's the correct procedure?
================================================
the same as the code I've provided in Q1
I'll update you as soon as I get any update. Meanwhile, if you have any
other questions or ideas, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.