如何在 ASP.NET 中设置无 SSL 的基本身份验证

发布于 2024-11-17 00:03:54 字数 2888 浏览 2 评论 0原文

各位,

我在 IIS 7 中有一个 asmx Web 服务,仅启用了基本身份验证。

我正在尝试在处理 SSL 之前在本地计算机上测试基本身份验证。

使用以下代码进行测试时...

        [TestMethod]
    public void TestMethod1()
    {
        MyCompanyExternalService.CClaim claim = new MyCompanyExternalService.CClaim();
        claim.Airline = "AA";
        claim.OrigCty = "MCO";
        claim.PaxFN = "John";
        claim.PaxLN = "Smith";
        claim.FileRef = "DL123321";
        claim.OrigDate = Convert.ToDateTime("1/1/2001");
        claim.ClaimFor = MyCompanyExternalService.EReasonsForClaim.Pilferage;
        claim.AirlineClaimStatus = "Open";


        MyCompanyExternalService.wsMyCompanyImportSoapClient MyCompanyImportSoapClient 
            = new MyCompanyExternalService.wsMyCompanyImportSoapClient("wsMyCompanyImportSoap");
        MyCompanyImportSoapClient.ClientCredentials.UserName.UserName = "My-PC\\chron";
        MyCompanyImportSoapClient.ClientCredentials.UserName.Password = "********";
        Assert.IsTrue(MyCompanyImportSoapClient.SubmitClaim(claim));
    }

.. 我收到以下错误:

HTTP 请求未经授权 客户端身份验证方案“基本”。 收到的认证标头 来自服务器的信息是“基本” 领域=“本地主机”'。

innerException:远程服务器 返回错误:(401) 未经授权。

这是我的 app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="wsMyCompanyImportSoap" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Basic" realm="" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/MyCompany/MyCompanyWebServiceApp/wsMyCompanyImport.asmx"
                binding="basicHttpBinding" bindingConfiguration="wsMyCompanyImportSoap"
                contract="MyCompanyExternalService.wsMyCompanyImportSoap"
                name="wsMyCompanyImportSoap" />
        </client>
    </system.serviceModel>
</configuration>

任何人都可以发现我的问题吗?

Folks,

I have an asmx web sevice being hotes in IIS 7 with only basic authentication enabled.

I am trying to test the basic authentication on my local machine before dealing with the SSL.

When testing using the following code...

        [TestMethod]
    public void TestMethod1()
    {
        MyCompanyExternalService.CClaim claim = new MyCompanyExternalService.CClaim();
        claim.Airline = "AA";
        claim.OrigCty = "MCO";
        claim.PaxFN = "John";
        claim.PaxLN = "Smith";
        claim.FileRef = "DL123321";
        claim.OrigDate = Convert.ToDateTime("1/1/2001");
        claim.ClaimFor = MyCompanyExternalService.EReasonsForClaim.Pilferage;
        claim.AirlineClaimStatus = "Open";


        MyCompanyExternalService.wsMyCompanyImportSoapClient MyCompanyImportSoapClient 
            = new MyCompanyExternalService.wsMyCompanyImportSoapClient("wsMyCompanyImportSoap");
        MyCompanyImportSoapClient.ClientCredentials.UserName.UserName = "My-PC\\chron";
        MyCompanyImportSoapClient.ClientCredentials.UserName.Password = "********";
        Assert.IsTrue(MyCompanyImportSoapClient.SubmitClaim(claim));
    }

.. I receive the following error:

The HTTP request is unauthorized with
client authentication scheme 'Basic'.
The authentication header received
from the server was 'Basic
realm="localhost"'.

innerexception: The remote server
returned an error: (401) Unauthorized.

Here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="wsMyCompanyImportSoap" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Basic" realm="" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/MyCompany/MyCompanyWebServiceApp/wsMyCompanyImport.asmx"
                binding="basicHttpBinding" bindingConfiguration="wsMyCompanyImportSoap"
                contract="MyCompanyExternalService.wsMyCompanyImportSoap"
                name="wsMyCompanyImportSoap" />
        </client>
    </system.serviceModel>
</configuration>

Can anyone spot my problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不美如何 2024-11-24 00:03:54

我使用几个管理员用户来测试 Web 服务的基本身份验证。我不知道为什么,但他们失败了。最后,我尝试使用一个测试用户进行身份验证,该用户除了 Web 服务目录上的 ACL 之外没有任何权限,并且成功了。

I was using a couple of admin users to test the web service's Basic Authentication. I do not know why, but they failed. Finally I tried authenticating with a test user which had no privileges except for the ACL on the web service directory, and it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文