我有一个asp.net mvc 4 Web应用程序,我在其中创建了一个自定义成员资格提供程序(继承自MembershipProvider基类)。在同一个解决方案中,但在另一个项目中,我有一个wcf服务,我想使用我的成员资格提供程序中的ValidateUser方法(称为KinematMembershipProvider)对用户进行身份验证
这是我的服务界面
[ServiceContract]
public interface IKinematService
{
[OperationContract]
bool AuthenticateUser(string username, string password);
}
和实际服务
public class KinematService : IKinematService
{
public bool AuthenticateUser(string username, string password)
{
KinematMembershipProvider membershipProvider = (KinematMembershipProvider)Membership.Providers["KinematMembershipProvider"];
return membershipProvider.ValidateUser(username, password);
}
}
这是我的app.config文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--configSections-->
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<!--appSettings-->
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<!--connectionStrings-->
<connectionStrings>
<add name="KinematDbContext" providerName="System.Data.SqlClient"
connectionString="Data Source=.;Initial Catalog=KinematDatabase;Integrated Security=SSPI;" />
</connectionStrings>
<!--system.web-->
<system.web>
<!--compilation-->
<compilation debug="true" />
<!--membership-->
<membership defaultProvider="KinematMembershipProvider">
<!--providers-->
<providers>
<add name="KinematMembershipProvider" type="Kinemat.Web.Infrastructure.KinematMembershipProvider"
connectionStringName="KinematDbContext" enablePasswordRetrieval="true" enablePasswordReset="true"
requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" passwordFormat="Encrypted" />
</providers>
</membership>
</system.web>
<!--system.serviceModel-->
<system.serviceModel>
<!--services-->
<services>
<service name="Kinemat.WebServices.KinematService" behaviorConfiguration="ProviderServiceBehavior">
<endpoint address="http://localhost:52174/WcfServices/Kinemat" binding="wsHttpBinding" bindingConfiguration="MembershipBinding"
contract="Kinemat.WebServices.IKinematService">
</endpoint>
</service>
</services>
<!--bindings-->
<bindings>
<wsHttpBinding>
<binding name="MembershipBinding">
<security mode ="Message">
<message clientCredentialType ="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<!--behaviors-->
<behaviors>
<!--serviceBehaviors-->
<serviceBehaviors>
<behavior name="ProviderServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="KinematMembershipProvider" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<!--entityFramework-->
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
当我运行我的服务时,我收到以下错误 System.TypeLoadException:无法从程序集'System.Web,Version = 4.0.0.0,Culture = neutral加载类型'Kinemat.Web.Infrastructure.KinematMembershipProvider'公钥= b03f5f7f11d50a3a”。
我无法弄清楚它为什么要在System.Web程序集中搜索。请问您有什么建议吗?如果需要,请询问任何其他信息。谢谢。
答案 0 :(得分:1)
它试图在System.Web
程序集中找到它,因为您没有在配置中指定它应该实际搜索您的提供程序。尝试修改您的配置以包含如下所示的程序集名称:
<providers>
<add name="KinematMembershipProvider" type="Kinemat.Web.Infrastructure.KinematMembershipProvider, Assembly.Name.Where.Provider.Resides" .../>
</providers>