我有一个 Web 应用程序和一个 WPF 应用程序共享一个实用程序的支持项目。
当试图让我的自定义会员用户配置文件在 WPF 项目上工作时,我收到一个错误并且不确定要查找什么。
从 WPF 项目调用支持项目中的 GetUser 方法时出现错误,错误是 -
无法从程序集“System.Web,版本=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 项目中无法调用它的应用程序配置是 -
<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;