HttpContext.Current.Profile.IsAnonymous == true, but ASPXAUT

Posted by Community Admin on 03-Aug-2018 18:09

HttpContext.Current.Profile.IsAnonymous == true, but ASPXAUTH cookie set

All Replies

Posted by Community Admin on 09-May-2011 00:00

I'm using the ASP.NET membership and roles provider wrapper in 4.1. I'm able to log in, but HttpContext.Current.Profile.IsAnonymous is true while decrypting the authorization cookie shows the user is logged in (FormsAuthentication.Decrypt(Request.Cookies[".ASPXAUTH"].Value).Name).

I wanted to get the username of the current user, which I can get through the cookie instead of via HttpContext.Current.Profile.Username, but I figure if the profile isn't getting set, I'm doing something wrong and I should fix it.

Edit:
I suspect I need the profile to be populated to restrict which roles have access to which pages. I'm logged in with the right role, but I keep getting "System.UnauthorizedAccessException: You are not authorized to 'View a page' ('Pages')."

Thanks

Posted by Community Admin on 10-May-2011 00:00

I looked at HttpContext.Current.User (which from my understanding, HttpContext.Current.Profile is dynamically created based on HttpContext.Current.User).

Even though the Forms Authentication Cookie is set, the HttpContext.Current.User is still not authenticated and is anonymous. I was surprised the authentication type was Sitefinity.

HttpContext.Current.User
    Id: 00000000-0000-0000-0000-000000000000
    Provider:
    Ticket:
    AuthenticationType: Sitefinity
    IsAuthenticated: False
    Name: Anonymous

I've added the profile to the web.config

<profile enabled="true" defaultProvider="MyProfileProvider">
  <providers>
    <add name="MyProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MyDB" applicationName="/" />
  </providers>
  <properties>
    <add allowAnonymous="false" name="PersonId" type="int" />
  </properties>
</profile>

UserProfilesConfig.config
<userProfilesConfig xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="4.1.1339.0">
    <providers>
        <add version="4.1.1339.0" name="OpenAccessProfileProvider" />
    </providers>
</userProfilesConfig>

I noticed under advanced settings, the membership, role, and security providers don't have anything about System.Web.Profile.SqlProfileProvider. Do I need to create a new provider here?

Posted by Community Admin on 12-May-2011 00:00

Hi Eric,

We don't have Profile provider wrappers yet. In our Membership wrapper's ValidateUser() method I call the wrapped ASP.NET membership provider ValidateUser() - I guess this is enough for the Forms authentication cookie to be issued but there is also this method

FormsAuthentication.SetAuthCookie(userName, true);

I'm just not sure if both cookies won't interfere with each other. I will have to investigate and get back to you on this matter.

All the best,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 02-Jun-2011 00:00

guys,

i am am not getting the FirstName when I use the following

 

 

var manager = UserManager.GetManager();

 

 

 

 

var currentUser = manager.GetUser(SecurityManager.GetCurrentUser().Identity.Name);

 

 

command.Parameters.Add(

 

new SqlParameter("@firstname", SqlDbType.NVarChar, 50)).Value = currentUser.FirstName;

 

 

command.Parameters.Add(

 

 

new SqlParameter("@lastname", SqlDbType.NVarChar, 50)).Value = currentUser.LastName;

 

FirstName goes to the database as null. Why?

Thanks,
Andrei

Posted by Community Admin on 03-Jun-2011 00:00

Hi Andrei,

Could you try to use the code below to get the FirstName

var profileTypeName = UserProfilesHelper.GetProfileTypeName(typeof(SitefinityProfile));
 
var upm = UserProfileManager.GetManager();
 
// pass the current user id - userId
 
var profile = upm.GetUserProfile(userId, profileTypeName) asSitefinityProfile;
 
if(profile != null)
 
 
    var fn = profile.FirstName;
 


Regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 03-Jun-2011 00:00

Ivan,

Again, thanks for the code. It worked. Sorry for posting it here too as well as in the ticket.
It was a bit of an emergency.

Thanks,
Andrei

This thread is closed