2

So I have an asp.net Web Application (Not Web Site) that I am trying to support profiles for anonymous users. I have a form and I want anonymous users to be able to enter their name and email only once, and have that information automatically accessible on the next load for them.

In my Web.config I have anonymous ID setup like so:

<anonymousIdentification enabled="true" cookieless="AutoDetect" />

I have my profile section setup like this:

<profile defaultProvider="SqlProvider" enabled="true" inherits="QA_Web_Tools.UserProfile">
  <providers>
    <clear />
    <add connectionStringName="QAToolsConnectionString" name="SqlProvider"
         type="System.Web.Profile.SqlProfileProvider" />
  </providers>
</profile>

Finally, due to my app being a Web App and not a Web Site, I am using the profiles via this custom object:

public class UserProfile : ProfileBase
{
    public static UserProfile GetUserProfile(string username)
    {
        return Create(username) as UserProfile;
    }

    public static UserProfile GetUserProfile()
    {
        return Create(Membership.GetUser().UserName) as UserProfile;
    }

    [SettingsAllowAnonymous(true)]
    public string FullName
    {
        get { return base["FullName"] as string; }
        set { base["FullName"] = value; }
    }

    [SettingsAllowAnonymous(true)]
    public string BuildEmail
    {
        get { return base["BuildEmail"] as string; }
        set { base["BuildEvmail"] = value; }
    }
}

This code is based off of this reference.

The issue is that that code does not support anonymous users, or if it does I don't know how. I can't use the GetUserProfile() method with no parameters because if the user is anonymous, Membership.GetUser() is null. I could pass in the anonymous ID token into the first GetUserProfile(string username) method but I cant' find any way to get the anonymous ID token for the current user.

Does anyone know how to get this information? Google doesn't seem to be returning useful results.

Thanks,

KallDrexx
  • 27,229
  • 33
  • 143
  • 254

1 Answers1

2

Success!

I changed:

public static UserProfile GetUserProfile()
{
    return Create(Membership.GetUser().UserName) as UserProfile;
}

to

    public static UserProfile GetUserProfile()
    {
        return HttpContext.Current.Profile as UserProfile;
    }

and now it works!

KallDrexx
  • 27,229
  • 33
  • 143
  • 254
  • may I ask you a question, this option gives you the chance to track anonymous users with the possibility to take that configuration - eg: guid - when they finally register in the platform? brgds – s_h Nov 30 '11 at 17:02
  • 1
    I'm actually not sure if this is done automatically, but I doubt it. One way you could handle this is in the "Create account" logic you keep track of the user's previous anonymous information, and after registration you copy that data into their new account. – KallDrexx Nov 30 '11 at 19:28