summaryrefslogtreecommitdiffstats
path: root/src/Startup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Startup.cs')
-rw-r--r--src/Startup.cs78
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