I have created a WebAPI application on my local machine using Windows Authentication.
I have also created an MVC 5 application and I am trying to connect to my WebAPI with the following code:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:52613/api/acmeco/");
var result = client.GetAsync("assignees/get").Result;
string resultContent = result.Content.ReadAsStringAsync().Result;
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
assignees = json_serializer.DeserializeObject(resultContent);
}
The problem is: Everytime I try to connect, either via the MVC 5 app, or via Fiddler, I get a 401 Unauthorized
error.
I have tried a variety of solutions to fix this issue, including but not limited to the following:
http://support.microsoft.com/kb/896861/en-us
Does anyone know how I can call my local WebAPI from my local MVC 5 app?
Edit: I have also tried adding CORS (cross-origin scripting) to the WebAPI like so, but there seems no effect on the 401 error:
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class AssigneesController : ApiController
{
public Assignees AssigneeRepo = new Assignees();
// GET api/values
public IEnumerable<Assignee> Get(string @namespace)
{
return AssigneeRepo.GetAssigneesForTenant(@namespace);
}
}
However, I can access localhost:52613/api/acmeco/assignees/get directly from my browser.