Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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# 无法访问OWIN自托管服务-IntegratedWindowsAuthentication-401_C#_.net_Authentication_Asp.net Web Api2_Owin - Fatal编程技术网

C# 无法访问OWIN自托管服务-IntegratedWindowsAuthentication-401

C# 无法访问OWIN自托管服务-IntegratedWindowsAuthentication-401,c#,.net,authentication,asp.net-web-api2,owin,C#,.net,Authentication,Asp.net Web Api2,Owin,我有一个OWIN Web API(控制台应用程序)。使用IntegratedWindowsAuthentication进行保护: /// <summary> /// This code configures Web API. The Startup class is specified as a type /// parameter in the WebApp.Start method. /// </summary> /// <param name="appBuil

我有一个OWIN Web API(控制台应用程序)。使用IntegratedWindowsAuthentication进行保护:

/// <summary>
/// This code configures Web API. The Startup class is specified as a type
/// parameter in the WebApp.Start method.
/// </summary>
/// <param name="appBuilder">app builder.</param>
public void Configuration(IAppBuilder appBuilder)
{
    // Configure Web API for self-host. 

    HttpConfiguration config = new HttpConfiguration();

    HttpListener listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"];
    listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

    appBuilder.UseWebApi(config);
}
我做错了什么-(

var requestUrl = ConfigurationManager.AppSettings["CTIListener"] + "CallDeliveryMonitor";
var request = (HttpWebRequest)WebRequest.Create(requestUrl);
request.PreAuthenticate = true;
//request.Credentials = new NetworkCredential("ashleighg", "xxxx", "xxxx"); //401 on specific credentials as well
request.UseDefaultCredentials = true;
request.Method = "GET";
request.ContentLength = 0;
request.ContentType = "application/json";

using(var response = (HttpWebResponse)request.GetResponse())
{
    //....
}