Last active
December 22, 2023 11:40
BlazorAppPart2/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BlazorAppPart2.Components; | |
using Microsoft.AspNetCore.Authorization; | |
using Microsoft.AspNetCore.Mvc.Authorization; | |
using Microsoft.Identity.Web; | |
using Microsoft.Identity.Web.UI; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration); | |
builder.Services.AddHttpContextAccessor(); | |
builder.Services.AddControllersWithViews(options => | |
{ | |
var policy = new AuthorizationPolicyBuilder() | |
.RequireAuthenticatedUser() | |
.Build(); | |
options.Filters.Add(new AuthorizeFilter(policy)); | |
}).AddMicrosoftIdentityUI(); | |
// Add services to the container. | |
builder.Services.AddRazorComponents() | |
.AddInteractiveServerComponents(); | |
builder.Services.AddRazorPages(); | |
builder.Services.AddServerSideBlazor(); | |
var app = builder.Build(); | |
// Configure the HTTP request pipeline. | |
if (!app.Environment.IsDevelopment()) | |
{ | |
app.UseExceptionHandler("/Error", createScopeForErrors: true); | |
// 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.UseHttpsRedirection(); | |
app.UseStaticFiles(); | |
app.UseAntiforgery(); | |
app.MapControllers(); | |
app.MapRazorComponents<App>() | |
.AddInteractiveServerRenderMode(); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment