gpt4 book ai didi

c# - WCF 自定义身份验证 - HTTP 状态 401 : Unauthorized

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:11 25 4
gpt4 key购买 nike

WCF 服务 WebConfig(部分)。

    <services>
<service name="Bricks99.LicensingServer.LicensingService"
behaviorConfiguration="Bricks99ServiceBehavior">
<!-- use base address specified above, provide one endpoint -->
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="Bricks99Binding"
contract="Bricks99.LicensingServer.ILicensingService" />
<!--<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />-->
</service>
</services>
<basicHttpBinding>
<binding name="Bricks99Binding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Bricks99.LicensingServer.CCustomValidatorClass, Bricks99.LicensingServer"/>
</serviceCredentials>

客户端是 ASP.NET 2.0

LicensingService service = new LicensingService();
//Authentication
CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(service.Url), "Basic", new NetworkCredential("Test", "1234567"));
service.Credentials = credCache;
service.PreAuthenticate = true;
service.UseDefaultCredentials = false;
result = service.VerifyLicenseKey(licenseKey, string.Empty);

结果始终是请求失败,HTTP 状态为 401:未经授权。我还关闭了文件夹的匿名访问。它仍然无法正常工作。关于如何正确设置凭据的任何想法?

编辑:似乎是重写的方法

public override void Validate(string userName, string password)
{
try
{
if(userName != "Test" || password != "1234567")
{
throw new FaultException("The provided credentials are invalid.");
}
}
catch(FaultException ex)
{
LicensingData.Operations.LogError(ex);
}
}

永远不会被击中。

最佳答案

经过数小时的研究,我发现托管服务提供商默认不允许基本身份验证。要使自定义身份验证起作用,必须在 IIS 中启用基本身份验证。

关于c# - WCF 自定义身份验证 - HTTP 状态 401 : Unauthorized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4482435/

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