Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我从IIS收到此请求的空白身份验证标头?_C#_Authentication_Iis_Iis 7 - Fatal编程技术网

C# 为什么我从IIS收到此请求的空白身份验证标头?

C# 为什么我从IIS收到此请求的空白身份验证标头?,c#,authentication,iis,iis-7,C#,Authentication,Iis,Iis 7,在我的组织(带域/Active Directory环境的标准windows)中,我们有一个供应商应用程序,它在单个网站下使用IIS 7.5和多个IIS应用程序。要使用此产品的API,将运行一个安装可执行文件,该文件将添加一个附加的IIS应用程序作为单个网站的一部分。安装提供了Basichtp或Windows身份验证,我选择了Windows 我现在按照他们的说明使用API(Get a Name示例的C版本): 我在Windows Visual Studio 2012中创建了一个C#控制台应用程序,

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

我现在按照他们的说明使用API(Get a Name示例的C版本):

我在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();
    }
}
}
根据我在windows身份验证API安装过程中的选择,我希望响应头类似于“NTLM,协商”,而不是空/空值

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


谢谢。

在Alberto指出正确的方向后,我发现IIS没有“安装”Windows身份验证。有关的指示如下:

然后必须启用它:


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

您有这个问题,因为您没有通过IIS进行身份验证。请尝试指定NTLM凭据类型,而不是Windows。将传输元素的clientCredentialType属性更改为“NTLM”后,我收到了相同的错误,但将“协商”改为“NTLM”。
<?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>
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was ''.