I have a OWIN Web API (console application). Secured with 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);
}
I can connect using SOAPUI and NTLM authentication. It works perfectly.
I get a 401 when I try and connect through .Net.
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())
{
//....
}
What am I doing wrong? :-(