I created a server-side blazor application with Windows authentication. It works fine and returns the data from the database when running using IIS Express in Visual Studio 2019.
try
{
var filtered = _context.Trades
.Where(.....)
.ToListAsync(cancellationToken)
.ConfigureAwait(false);
// ....
}
catch (Exception ex)
{
// .... will display the exception message
}
Then I changed it to Kestrel. I expected to raise exception because I haven't do anything to make Kestrel to work with Windows authentication.
However, it doesn't raise any exception. The following information can be found in the output window.
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService: Information: Authorization failed.
How to make sure it raises the exception?
BTW, how to make Kestrel works with Windows authentication?
Startup.cs updated for the answer.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using BlazorApp1.Data;
using Microsoft.AspNetCore.Authentication.Negotiate;
namespace BlazorApp1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
services.AddSingleton<WeatherForecastService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseAuthentication();
app.UseAuthorization();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}