profile values sometimes empty?

G

Guest

I've added a number of additional properties to my profile. Sometimes, the
values are populated when the user is retrieved from the database, but
sometimes the values are empty/default. How can I make sure that the values
are always populated correctly?

Further example, my website is working reliably enough, but I'm trying to
access the user profiles from an offline application, and very few of the
custom properties are being returned to my offline application (whereas they
are still visible in the online app).

3 questions:

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.

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>)

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?
 
S

Steven Cheng[MSFT]

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(ProfileAuthenticationOption.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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hello Eric,

I have just performed some further test to loop through all the properties
of each user in profile database in non-ASP.NET context and that also
worked well.

I've used a winform application which duplicate the same <profile> setting
with an ASP.NET web application. And the following code can correct dump
all the users(include both authenticated and anonymous identified users):

=========================
public partial class Form1 : Form
{
SqlProfileProvider _profile;

public Form1()
{
InitializeComponent();
}

private void btnDump_Click(object sender, EventArgs e)
{
Dump_Profile();
}

private void Dump_Profile()
{

ProfileInfoCollection pis =
ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);

txtOutput.Text += "\r\n=========Total Profile Count: " +
pis.Count + "==========";
txtOutput.Text += "\r\n\r\n";

foreach (ProfileInfo pi in pis)
{
ProfileBase pb = ProfileBase.Create(pi.UserName);

txtOutput.Text += "\r\n\tProfile for " + pi.UserName +"\t";

foreach (SettingsProperty sp in ProfileBase.Properties)
{
txtOutput.Text += "\r\n****" + sp.Name + "(" +
sp.PropertyType.Name + "): " + pb.GetPropertyValue(sp.Name);
}

txtOutput.Text += "\r\n";
}


}

private void Form1_Load(object sender, EventArgs e)
{
_profile = new SqlProfileProvider();


}
}

=======================================

One thing I'm wondering is whether you've used custom data object(custom
class) that will need particular serialiation. I haven't tried this so far.

Anyway, please feel free to let me know if you have any questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

I am using WinForms/Console application to read these profiles. my app.config
contains a <system.web> with all the same profile contents, except a
different profile provider. The profiles were originally stored by using
Community Server. But lookin at their code, it looks like it should still
store the data the same. Do you think that could be the problem? Is the
deserialization of the profile bag that sensitive?
 
G

Guest

I am using WinForms/Console application to read these profiles. my
app.config
contains a <system.web> with all the same profile contents, except a
different profile provider. The profiles were originally stored by using
Community Server. But lookin at their code, it looks like it should still
store the data the same. Do you think that could be the problem? Is the
deserialization of the profile bag that sensitive?

I dug into their provider with reflector, and the are not doing anything
strange in there. So I replaced the CS profile provider with the MS standard
SQL provider, and the site still works. And all profile data is showing up
still. Unfortunately, my WinForms app still refuses to load a majority of my
custom fields.

Fields like these are just empty when I load from my WinForms application.
But are populated just fine on my webserver.

<add name = "preferredLanguage" type="string"/>
<add name = "newsletterOptOut" type="System.Boolean"/>
<add name = "alternateEmail" type="string"/>
 
S

Steven Cheng[MSFT]

Hello Eric,

Thanks for your reply.

Yes, from the reflector diassembled code, the SqlServer service providers
can be runnining in non-ASP.NET context as well. I've also tried this
(membership, role, profile providers...) in a winform application and that
works. My local test also use some simple type properties(two string
properties ...) and I've also enabled anonymousIdentification. Currently,
I haven't found any particular difference from yours an my offline
application, are you using the similar code to query the profile db as I
posted in the previous message?

If you feel necessary, you can ping me at (e-mail address removed) and I can
send you my test winform project.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hello Eric,

How are you doing on this issue, have you got any progress. Or if you do
feel it hard to generate a simple repro page and this is an urgent issue, I
would suggest you contact the CSS for further assistance.

http://support.microsoft.com/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

I'm finding it rather easy to reproduce, actually. There must be something
simple that I am missing. I'm getting some of the profile values, and all the
rest of the fields are coming back, but empty. Values saved with one app are
not available to the other.

I'm using identical code for the profile provider in my app and web.config
files, but there's definately something wierd going on.

Can anyone else confirm that they are able to read profile values from a
database written by CommunityServer? I've upgraded to 2.1 and am using the
aspnet2 membership option.
 
S

Steven Cheng[MSFT]

Thanks for your reply Eric,

It seems a bit unexpected that your offline app can not get the value. Do
feel necessary I send you a test application and you can customize it so as
to repro the behavior. thus, I can perform some local tests against it.

BTW, what's the community server you mentioned?


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Eric,

I have just sent you my test applications. Please feel free to post here if
you have any new finding.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top