【问题标题】:How to set up Basic Authentication sans SSL in ASP.NET如何在 ASP.NET 中设置无 SSL 的基本身份验证
【发布时间】:2011-09-21 07:50:26
【问题描述】:

伙计们,

我有一个 asmx 网络服务,它是 IIS 7 中的热点,只启用了基本身份验证。

在处理 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) Unauthorized.

这是我的 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>

谁能发现我的问题?

【问题讨论】:

    标签: asp.net web-services basic-authentication


    【解决方案1】:

    请参考以下链接。这可能会对您有所帮助。

    http://ozkary.blogspot.in/2011/05/http-request-is-unauthorized-with.html

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-19
        • 2012-03-05
        • 2015-10-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-13
        • 1970-01-01
        • 2013-12-28
        相关资源
        最近更新 更多