gpt4 book ai didi

c# - 具有自定义 MembershipProvider 且没有 X.509 证书的 WCF,可能吗?

转载 作者:太空宇宙 更新时间:2023-11-03 20:34:48 24 4
gpt4 key购买 nike

我想根据自定义成员资格和角色提供者对 WCF 服务的用户进行身份验证,但我不想必须使用证书来保护两者之间的流量。

是否可以使用 basicHttpBinding,在没有证书的情况下传递自定义凭据?

我之所以问,是因为我有一个 WCF 服务,所有成员(member)提供程序管道等都通过配置连接并托管在 IIS 下,但用户详细信息没有传递到 IIS。

我有一个网络安全的 WAN,所以我不担心消息加密。

已开启ASP.Net兼容,配置如下。都是 .Net 4.0;

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<membership defaultProvider="DemoMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="DemoMembershipProvider" type="DemoMembershipProvider" connectionStringName="SqlConn" applicationName="TestProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Clear" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="DemoRoleProvider" >
<providers>
<clear/>
<add name="DemoRoleProvider" connectionStringName="blah" applicationName="TestProvider" type="DemoRoleProvider" />
</providers>
</roleManager>
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<services>
<service name="DataService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BindingConfiguration" contract="IDataService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BindingConfiguration">
<security mode="None">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="DemoMembershipProvider" />
</serviceCredentials>
<serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="DemoRoleProvider" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

客户端代码为;

            Console.WriteLine("Calling with valid credentials");
using (var y = new DataServiceRef.DataServiceClient())
{
y.ClientCredentials.UserName.UserName = "ryan";
y.ClientCredentials.UserName.Password = "password";
Console.WriteLine("Result: {0}", y.GetData("blah"));
}

最佳答案

您必须使用自定义绑定(bind),因为默认绑定(bind)不支持在没有安全通道(传输或消息安全都需要证书)的情况下发送用户名和密码。使用此自定义绑定(bind):

<customBinding>
<binding name="UsernamePasswordOverHttp">
<textMessageEncoding messageVersion="Soap11" />
<security
authenticationMode="UserNameOverTransport"
messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
allowInsecureTransport="true" />
<httpTransport />
</binding>
</customBinding>

另一个解决方案是使用 ClearUserNameBinding .

关于c# - 具有自定义 MembershipProvider 且没有 X.509 证书的 WCF,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5531377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com