diff options
| author | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
| commit | 3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch) | |
| tree | 734ca81d7d0841d8863e3f523ebba14c282dc681 /src/Startup.cs | |
| download | fagprove-master.tar.xz fagprove-master.zip | |
Diffstat (limited to 'src/Startup.cs')
| -rw-r--r-- | src/Startup.cs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Startup.cs b/src/Startup.cs new file mode 100644 index 0000000..bc30fe3 --- /dev/null +++ b/src/Startup.cs @@ -0,0 +1,78 @@ +using IOL.Fagprove.Utilities; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; + +namespace IOL.Fagprove +{ + 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. + public void ConfigureServices(IServiceCollection services) + { + services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) + .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => + { + options.LoginPath = new PathString("/"); + options.LogoutPath = new PathString("/"); + options.SlidingExpiration = true; + options.AccessDeniedPath = new PathString("/"); + options.Validate(); + }); + services.AddAuthorization().AddInternalUserPolicies(); + services.AddAppDbContext(Configuration); + services.AddServices(); + services.AddRazorPages(options => + { + options.Conventions.AuthorizeFolder("/app"); + options.Conventions.AddPageRoute("/login", ""); + }).AddRazorRuntimeCompilation(); + services.Configure<RouteOptions>(options => + { + options.LowercaseUrls = true; + options.LowercaseQueryStrings = true; + }); + services.AddControllers(); + } + + // 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(); + app.UseHttpsRedirection(); + } + else + { + app.UseExceptionHandler("/error"); + } + + app.UseStatusCodePages(); + app.UseSerilogRequestLogging(); + app.UseStaticFiles(); + app.UseRouting(); + app.UseAuthentication(); + app.UseCookiePolicy(Config.CookiePolicyOptions); + app.UseAuthorization(); + app.UseEndpoints(endpoints => + { + endpoints.MapRazorPages(); + endpoints.MapControllers(); + }); + } + } +}
\ No newline at end of file |
