C# 无法访问OWIN自托管服务-IntegratedWindowsAuthentication-401
我有一个OWIN Web API(控制台应用程序)。使用IntegratedWindowsAuthentication进行保护: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
/// <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())
{
//....
}