Profile.IsAnonymous always = true

R

robertm

Hello.

I have enabled Membership on my .NET application. I can add users,
assign them to roles, and log in and out.
the roles work perfectly, however the following code:

bool amIloggedIn = Profile.IsAnonymous;

amIloggedIn is alway = true;

whether I am logged in or not the isAnonymous property in the profile
is alway true, and the username does not get set, but the roles
provider recognized that I am logged in and gives me access to
restricted sub-directories.

Can anyone help me out here?
 
R

robertm

Hello.

I have enabled Membership on my .NET application. I can add users,
assign them to roles, and log in and out.
the roles work perfectly, however the following code:

bool amIloggedIn = Profile.IsAnonymous;

amIloggedIn is alway = true;

whether I am logged in or not the isAnonymous property in the profile
is alway true, and the username does not get set, but the roles
provider recognized that I am logged in and gives me access to
restricted sub-directories.

Can anyone help me out here?

I found a solution:

I think the problem is being caused by Context Issues. I am using a
MasterPage, and so when I login in, and I successfully logged in,
however when I go to another page the Profile is empty because the
context is different.

Work around:

To use the Profile, we need to re-initialize it:

if (Request.IsAuthenticated)
{
Profile.Initialize(User.Identity.Name, true);
}

Keep in mind this will only work with forms based authentication.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top