Blazor server app with Windows authentication getting 401 unauthorized
I’m building a Blazor server application for an internal company use and using Windows authentication. The app is supposed to field updates from another app via an exposed controller. I am trying to test the controller and getting a 401 unauthorized however I try to hit it (Postman, browser, test Console app, from within the Blazor server app itself, etc.). I’m running .NET 6 and scaffolded the app using Visual Studio and selecting Windows Authentication from the Create Project wizard for Blazor server app. I’m running the app from Visual Studio using IIS Express option. Here is the simple test I set up in the Console app just trying to get a positive response from the controller:
public async Task GetUpdateTestTimerResult()
{
var client = new HttpClient();
client.BaseAddress = new Uri(“http://localhost:40871”);
var url = “api/updateTest”;
var value = await JsonSerializer.DeserializeAsync
(await client.GetStreamAsync(url), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
return value;
}
I’ve tried setting the AllowAnonymous attribute on the controller but no dice there. How do I expose a controller that will allow an outside application (also internal to the company/on premises) access?
I’m building a Blazor server application for an internal company use and using Windows authentication. The app is supposed to field updates from another app via an exposed controller. I am trying to test the controller and getting a 401 unauthorized however I try to hit it (Postman, browser, test Console app, from within the Blazor server app itself, etc.). I’m running .NET 6 and scaffolded the app using Visual Studio and selecting Windows Authentication from the Create Project wizard for Blazor server app. I’m running the app from Visual Studio using IIS Express option. Here is the simple test I set up in the Console app just trying to get a positive response from the controller: public async Task GetUpdateTestTimerResult()
{
var client = new HttpClient();
client.BaseAddress = new Uri(“http://localhost:40871”);
var url = “api/updateTest”;
var value = await JsonSerializer.DeserializeAsync
(await client.GetStreamAsync(url), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
return value;
} I’ve tried setting the AllowAnonymous attribute on the controller but no dice there. How do I expose a controller that will allow an outside application (also internal to the company/on premises) access? Read More