如何在 ASP.NET 中设置无 SSL 的基本身份验证
各位,
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参考以下链接。这可能对你有帮助。
http://ozkary.blogspot.in/2011/05 /http-request-is-unauthorized-with.html
Please refer to following link. This might help you.
http://ozkary.blogspot.in/2011/05/http-request-is-unauthorized-with.html
我使用几个管理员用户来测试 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.