【问题标题】:Why am I receiving a blank authentication header from IIS for this request?为什么我会收到来自 IIS 的针对此请求的空白身份验证标头?
【发布时间】:2013-11-12 18:35:15
【问题描述】:

在我的组织(具有域/Active Directory 环境的标准窗口)中,我们有一个供应商应用程序,它使用 IIS 7.5 和单个网站下的多个 IIS 应用程序。要使用此产品的 API,需要运行一个安装可执行文件,将附加的 IIS 应用程序添加为单个网站的一部分。安装提供 basicHttp 或 Windows 身份验证,我选择了 Windows。

我现在按照他们的说明使用 API(Get a Name 示例的 C# 版本):http://www.documentation.newdawn.com/api/

我在 Windows Visual Studio 2012 中创建了一个 C# 控制台应用程序,并使用“添加服务引用”菜单项来使用服务 URL 并创建客户端类。

我对 URL 中代码的唯一更改是使用 windows 身份验证而不是他们的 BasicHttp 示例:

using JustWareAPIClientConsoleApp.JustWareAPI;

namespace JustWareAPIClientConsoleApp
{
class Program
{
    static void Main(string[] args)
    {
        JustWareApiClient client = new JustWareApiClient();

        client.ClientCredentials.Windows.ClientCredential.Domain = "<domain>";
        client.ClientCredentials.Windows.ClientCredential.UserName = "<username>";
        client.ClientCredentials.Windows.ClientCredential.Password = "<password>";

        Name n = client.GetName(123, null);

        Console.WriteLine("Name: " + n.Last + "," + n.First);

        client.Close();

        Console.ReadLine();
    }
}
}

我没有对 App.config 文件进行任何更改:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="JustWareApi" messageEncoding="Mtom">
                    <security mode="Transport">
                        <transport clientCredentialType="Windows" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://<server>/JustWareAPI/JustWareApi.svc"
                binding="basicHttpBinding" bindingConfiguration="JustWareApi"
                contract="JustWareAPI.IJustWareApi" name="JustWareApi" />
        </client>
    </system.serviceModel>
</configuration>

当我运行客户端示例时,当它到达 GetName 方法调用时出现以下错误:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was ''.

根据我在 Windows 身份验证的 API 安装期间的选择,我期待响应标头类似于“NTLM,Negotiate”,而不是空白/空值。

不幸的是,我不太了解 IIS,但我的直觉告诉我,在站点或应用程序级别有一些设置,API 安装没有正确设置,我没有得到有效的身份验证标头。谁能告诉我为什么这个标题会这样回来?

谢谢。

【问题讨论】:

  • 您有这个问题是因为您没有通过 IIS 进行身份验证。尝试指定 NTLM 凭据类型,而不是 Windows。
  • 将传输元素的 clientCredentialType 属性更改为“Ntlm”后,我得到了同样的错误,但用“Ntlm”代替了“协商”。

标签: c# authentication iis iis-7


【解决方案1】:

在 Alberto 指出正确的方向后,我发现 Windows 身份验证没有为 IIS“安装”。此处的说明: http://weblogs.asp.net/zroiy/archive/2008/08/17/missing-windows-authentication-provider-for-iis-7-on-windows-server-2008.aspx

然后必须启用它: http://technet.microsoft.com/en-us/library/cc754628%28v=ws.10%29.aspx

执行这些步骤后,我不再收到 IIS 身份验证错误。

【讨论】:

    猜你喜欢
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    相关资源
    最近更新 更多