Need to login automatically based on windows login
Need to open windows login prompt for another API call
Need to login automatically based on windows login
Need to open windows login prompt for another API call
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Apr 13, 2023, 12:01 AM EDT
In your ASP.NET Core project, add the Microsoft.AspNetCore.Authentication.Negotiate NuGet package.
In your Startup.cs file, add the following lines of code to the ConfigureServices method:
This configures the authentication middleware to use Negotiate authentication.
This adds the authentication middleware to the middleware pipeline.
In your controller or action method, you can access the user's Windows identity using the User.Identity property.
To open the Windows login prompt for another API call, you can use the HttpClientHandler class to create a new instance of the HttpClient with Windows authentication enabled. Here's an example:
using (var handler = new HttpClientHandler { UseDefaultCredentials = true }) { using (var client = new HttpClient(handler)) { var response = await client.GetAsync("http://example.com/api/endpoint"); // Handle response } }Vishal YelveRank #178 · 13.6K reputationPosted Apr 13, 2023, 2:00 AM EDT
Hi Sree,
Do refer below link
https://www.c-sharpcorner.com/article/configure-windows-authentication-in-asp-net-core/
https://damienbod.com/2021/04/26/securing-an-asp-net-core-app-and-web-api-using-windows-authentication/