WPF会员提供商自定义用户配置文件

时间:2013-09-06 15:58:07

标签: c# wpf asp.net-membership

我有一个Web应用程序和WPF应用程序共享实用程序的支持项目。

当试图让我的自定义成员资格用户配置文件在WPF项目上工作时,我收到错误,并且不确定要查找的内容。

从WPF项目调用支持项目中的GetUser方法时发生错误,错误是 -

无法从程序集'System.Web,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'加载'APP.Support.UserProfile'类型。

用户个人资料代码为 -

namespace APP.Support
{
public class UserProfile : ProfileBase
{
    static public UserProfile CurrentUser
    {
        get
        {
            return (UserProfile)
                    (ProfileBase.Create(Membership.GetUser().UserName));
        }
    }

    public static UserProfile GetUser(string username)
    {
        return (UserProfile)
                    (ProfileBase.Create(username));
    }

    public string UserCode
    {
        get { return ((string)(base["UserCode"])); }
        set { base["UserCode"] = value; Save(); }
    }

    public string Name
    {
        get { return ((string)(base["Name"])); }
        set { base["Name"] = value; Save(); }
    }

    public string UserID
    {
        get { return ((string)(base["UserID"])); }
        set { base["UserID"] = value; Save(); }
    }
}

}

网络配置(有效)是 -

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="30">
  <providers>
    <clear/>
    <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="6" connectionStringName="MembershipConnectionString" applicationName="APP" enablePasswordRetrieval="false" maxInvalidPasswordAttempts="2147483647" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed"/>
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
  <providers>
    <clear/>
    <add connectionStringName="MembershipConnectionString" applicationName="APP" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
  </providers>
</roleManager>
<profile defaultProvider="SqlProvider" inherits="APP.Support.UserProfile">
  <providers>
    <clear/>
    <add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MembershipConnectionString" applicationName="APP"/>
  </providers>
</profile>

WPF项目中不能调用它的app配置是 -

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="30">
  <providers>
    <clear/>
    <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="6" connectionStringName="MembershipConnectionString" applicationName="APP" enablePasswordRetrieval="false" maxInvalidPasswordAttempts="2147483647" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed"/>
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
  <providers>
    <clear/>
    <add connectionStringName="MembershipConnectionString" applicationName="APP" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
  </providers>
</roleManager>
<profile defaultProvider="SqlProvider" inherits="APP.Support.UserProfile">
  <providers>
    <clear/>
    <add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MembershipConnectionString" applicationName="APP"/>
  </providers>
</profile>  

主叫代码是 -

Application.Current.Properties["UserName"] = username;

UserProfile profile = UserProfile.GetUser(username);

Application.Current.Properties["LoggedInUser"] = profile.Name;

1 个答案:

答案 0 :(得分:0)

如果其他人处于这种情况,那似乎是不可能的。

我最终在支持项目中编写了一些SQL方法来检索用户配置文件信息。

会员资格数据库中的个人资料信息以相当奇怪的方式存储,但它是可提取的 -

PropertyNames - UserCode:S:0:2:名称:S:2:9:UserID:S:11:8:

PropertyValues - XXTEST USER00000001