// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IStudentsDbService dbService) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Use(async(context, next) => { if (!context.Request.Headers.ContainsKey("Index")) { context.Response.StatusCode = StatusCodes.Status401Unauthorized; await context.Response.WriteAsync("Nie podałeś indeksu"); return; } var index = context.Request.Headers["Index"].ToString(); if (dbService.CheckStudentIndex(index) == null) { context.Response.StatusCode = StatusCodes.Status404NotFound; await context.Response.WriteAsync("Student o podanym numerze indeksu nie istnieje"); return; } await next(); }); app.UseMiddleware <LoggingMiddleware>(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }