1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / HttpContext.Current.Profile.IsAnonymous == true, but ASPXAUTH cookie set

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

6 posts, 0 answered
  1. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    09 May 2011
    Link to this post
    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
  2. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    10 May 2011
    Link to this post
    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?

  3. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    12 May 2011
    Link to this post
    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
  4. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    02 Jun 2011
    Link to this post
    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

  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Jun 2011
    Link to this post
    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
  6. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    03 Jun 2011
    Link to this post
    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
6 posts, 0 answered