コード例 #1
0
ファイル: Startup.cs プロジェクト: s16424/cwiczenia3
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, iStudentDbService service)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseMiddleware <LoggingMiddleware>();
            // - Index : sxxxx + spr w DB czy istnieje
            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Musisz podac numer indeksu");
                    return;
                }
                string index = context.Request.Headers["Index"].ToString();
                var stud     = service.GetStud(index);
                if (stud == null)
                {
                    context.Response.StatusCode = StatusCodes.Status404NotFound;
                    await context.Response.WriteAsync("Student not found");
                    return;
                }

                await next();
            });

            app.UseRouting(); // -- sprawddza co powinno odp na zadanie
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => // zwraca odp na zadanie
            {
                endpoints.MapControllers();
            });
        }
コード例 #2
0
 public EnrollmentsController(iStudentDbService service)
 {
     _service = service;
 }