开发者

ASP.NET ProfileBase.Create behavior when supplied with an existing username

When supplied with a username that already exists,开发者_C百科 does ProfileBase.Create return the ProfileBase associated with the existing user (and if the username does not exisit, creates a new user and returns the new user)?

Apologies for the trivial question, but MSDN documentation really is of little help.


Here's the code for ProfileBase.Create():

public static ProfileBase Create(string username, bool isAuthenticated)
{
    if (!ProfileManager.Enabled)
    {
        throw new ProviderException(SR.GetString("Profile_not_enabled"));
    }
    InitializeStatic();
    if (s_SingletonInstance != null)
    {
        return s_SingletonInstance;
    }
    if (s_Properties.Count == 0)
    {
        lock (s_InitializeLock)
        {
            if (s_SingletonInstance == null)
            {
                s_SingletonInstance = new DefaultProfile();
            }
            return s_SingletonInstance;
        }
    }
    HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
    return CreateMyInstance(username, isAuthenticated);
}


private static ProfileBase CreateMyInstance(string username, bool isAuthenticated)
{
    Type profileType;
    if (HostingEnvironment.IsHosted)
    {
        profileType = BuildManager.GetProfileType();
    }
    else
    {
        profileType = InheritsFromType;
    }
    ProfileBase base2 = (ProfileBase) Activator.CreateInstance(profileType);
    base2.Initialize(username, isAuthenticated);
    return base2;
}

Looks like it always returns a new instance of ProfileBase.


As I thought, the Create method actually retrieves the profile. Who designs these APIs?!

See also here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜