Advertisement
Guest User

Untitled

a guest
Jan 5th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | Help | 0 0
  1. // Program.cs
  2.  
  3. WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
  4.  
  5. builder.Services.AddControllers();
  6.  
  7. builder.Services.AddAuthentication(IISDefaults.AuthenticationScheme);
  8.  
  9. builder.Services.AddAuthorization(options =>
  10. {
  11.     options.FallbackPolicy = options.DefaultPolicy;
  12. });
  13.  
  14. WebApplication app = builder.Build();
  15.  
  16. app.UseHttpsRedirection();
  17.  
  18. app.UseAuthentication();
  19. app.UseAuthorization();
  20.  
  21. app.MapControllers();
  22.  
  23. app.Run();
  24.  
  25. // Controller
  26.  
  27. [Route("api/[controller]")]
  28. [ApiController]
  29. public class MyController : ControllerBase
  30. {
  31.     [HttpGet]
  32.     [Authorize]
  33.     public IActionResult Ping()
  34.     {
  35.         return Ok($"Ping Ok. Auth: {WindowsIdentity.GetCurrent()?.Name}");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement