Profile.IsAnonymous problem

M

Marco Assandri

Hi everybody,

I have a problem with this code.

'An anonymous username copied from the Username column of Aspnet_Users table
with IsAnonymous = True

dim SurelyAnonymousUsername = "b8119428-6420-4609-958b-ac0504f6f88b"
dim p as ProfileCommon
p = Profile.GetProfile(SurelyAnonymousUsername)

If p.IsAnoymous = True then ' This is False ??????????????

......

End If



It is impossible. Why p.IsAnonymous is False??

Thanks
 
S

S. Justin Gengo [MCP]

Marco,

When the profile system is running any user who comes to the site is added
to the anonymous user table and is assigned a guid to track them. (Not so
anonymous after all). The difference between an anonymous user and a
registered user isn't that the anonymous user isn't in the database it's
that the anonymous user isn't signed in. The code you are calling is
returning false, because the guid can't be found in the database at all.
Therefore the user isn't registered or anonymous.

Is that clear? Let me know if my explanation isn't clear enough and I'll
attempt to word it differently.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
M

Marco Assandri

Justin,
the user is in the aspnet_Users table and the column IsAnonymous of this
table is true.
When I debug the application the code run fine.
p = Profile.GetProfile(SurelyAnonymousUsername) return a real anonymous
profile and I can use it to retrieve all information about this anonymous
user.
All works fine except the IsAnonymous properties.
It's difficult to explain.
Try this code in the pageLoad event of one page to see what I mean:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load



'Now I create a profile equal to the current profile

Dim p As ProfileCommon = Profile.GetProfile(Profile.UserName)

Response.Write(p.IsAnonymous)

Response.Write("<br />")

Response.Write(Profile.IsAnonymous)

End Sub

The result is:

False
True

The p profile is not anonymous and the current profile is anonymous. But it
is impossible because they are the same profile with the same properties
except the IsAnonymous property.
I hope to have explained the problem.
 
S

S. Justin Gengo [MCP]

Marco,

I think the following article addresses what you're talking about:

http://odetocode.com/Articles/440.aspx

Here's an excerpt:

Notice we need to coerce the Profile object into a ProfileCommon reference
(the as ProfileCommon in the code). Since the ProfileCommon class is
generated by ASP.NET from web.config, so it's not possible for the
HttpContext class to know the definition of ProfileCommon. HttpContext has
to return a ProfileBase reference. The ProfileCommon class derives from
ProfileBase. All we need to do is cast the ProfileBase reference to a
ProfileCommon reference.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
M

Marco Assandri

Thanks Justin for your time,

I found a solution.
The ProfileCommon created by Profile.GetProfile(Username) are different from
the HttpContext profile.
They don't change automatically but I need to use the Save() sub.
The IsAnonymous property return always false except with the HttpContext
profile. To find if the different profile isAnonymous or not I did a query
on the aspnet_Users table column IsAnonymous.
Thanks for your help.
Sincerely,
Marco
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top