开发者

How do you get asp.net anonymous authentication token for profile support?

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,


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜