我有一个客户端和应用程序,它们设置为使用 ClientFormAuthenticationMembershipProvider 进行身份验证。在客户端,当应用程序启动时,系统会提示输入用户名和密码。服务器设置为接受这一点,并且 Web 应用程序应该允许该应用程序工作。我们正在建立一个新环境,但服务器端出现了一些问题(如果我们将客户端指向另一台服务器,它可以正常工作)。我们煞费苦心地检查了我们能想到的每一个细节,结果都是一样的:对 ValidateUser() 的调用会引发异常。我已经下载了一个网络嗅探器,在后台我可以看到当我尝试调用 Authentication_JSON_AppService.axd 时正在返回一条 302 消息。在服务器端,
客户端配置:
从我们的 FormMain.cs (它试图调用提供者)
if (!System.Web.Security.Membership.ValidateUser(null, null))
System.Windows.Forms.Application.Exit();
else
{
DoStartUp();
....
}
从我们的 FormLogin.cs(提示输入用户名和密码)注意:类继承 IClientFormsAuthenticationCredentialsProvider
public System.Web.ClientServices.Providers.ClientFormsAuthenticationCredentials GetCredentials()
{
if (this.ShowDialog() == DialogResult.OK)
{
return new ClientFormsAuthenticationCredentials(
textEditUsername.Text, textEditPassword.Text,
false);
}
else
{
return null;
}
}
从 app.config:
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<clear />
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="http://SERVERNAME/APPNAME/Authentication_JSON_AppService.axd" credentialsProvider="APPNAME.Windows.FormLogin, APPNAME.Windows" savePasswordHashLocally="False" />
</providers>
</membership>
在服务器端:
已为此应用程序配置 IIS 以进行匿名身份验证和表单身份验证。(我们正在运行 IIS 7.5、.NET 4.0、Windows Server 2008 R2)。我们在服务器上安装了 WCF 激活和 HTTP 激活功能。ApplicationPool 设置为 v4.0 Framework,未启用 32 位应用程序,Integrated PipelineMode,大多数其他值设置为默认值。
web.config 文件:
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" />
<roleService enabled="true" />
</webServices>
</scripting>
</system.web.extensions>
<authentication mode="Forms">
<forms name=".MDPSApp" loginUrl="~/Connect/Login.aspx" slidingExpiration="true" timeout="600000">
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
<membership defaultProvider="XYZ">
<providers>
<add name="XYZ" type="APPNAME.Web.Providers.MembershipProvider, APPNAME.Web" />
</providers>
</membership>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="DisableAutoCookieManagement" maxReceivedMessageSize="2147483647" allowCookies="false">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
</wsHttpBinding>
<behaviors>
<serviceBehaviors>
<behavior name="APPNAME.Application.Web.Services.AgenceMaster.ServiceAgenceMasterBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="None">
</serviceAuthorization>
</behavior>
<behavior name="APPNAME.Application.Web.Services.Agence.ServiceAgenceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="APPNAME.Application.Web.Services.AgenceMaster.ServiceAgenceMasterBehavior" name="APPNAME.Application.Web.Services.AgenceMaster.ServiceAgenceMaster">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="DisableAutoCookieManagement" contract="APPNAME.Services.AgenceMaster.IServiceAgenceMaster">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="APPNAME.Application.Web.Services.Agence.ServiceAgenceBehavior" name="APPNAME.Application.Web.Services.Agence.ServiceAgence">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="DisableAutoCookieManagement" contract="APPNAME.Services.Agence.IServiceAgence">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
APPNAME.Web.Providers.MembershipProvider 类扩展 System.Web.Security.MembershipProvider 并使用自定义代码覆盖 ValidateUser(string username, string password)。这个类在场景中没有被实例化或调用。
服务器端没有正确配置某些东西,否则服务器会知道如何正确解析 Authentication_JSON_AppService.axd 调用(在我看来不是这样)。任何想法或帮助表示赞赏!