Example #1
0
        /// <summary>
        /// Instantiates a new <see cref="SecurityHeadersMiddleware"/>.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="policy">An instance of the <see cref="SecurityHeadersPolicy"/> which can be applied.</param>
        public SecurityHeadersMiddleware(RequestDelegate next, SecurityHeadersPolicy policy)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (next == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            _next   = next;
            _policy = policy;
        }
        public SecurityHeadersMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, SecurityHeadersPolicy policy)
        {
            if (next == null)
            {
                throw new System.ArgumentNullException(nameof(next));
            }

            if (next == null)
            {
                throw new System.ArgumentNullException(nameof(policy));
            }

            _next   = next;
            _policy = policy;
        }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
        }
        app.UseSecurityHeaders(SecurityHeadersPolicy.CreateSecurityHeaderCollection(env));
        app.UseSwagger();
        app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Modules Registry API"));
        var supportedCultures = LanguageUtility.FullySupportedLanguages;

        app.UseRequestLocalization(options =>
        {
            options.AddSupportedCultures(LanguageUtility.FullySupportedLanguages);
            options.AddSupportedUICultures(LanguageUtility.FullySupportedLanguages);
            options.DefaultRequestCulture    = new RequestCulture(LanguageUtility.DefaultCulture);
            options.FallBackToParentCultures = true;
        });
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseApiUserAuthentication();
        app.UseCookiePolicy();
        app.UseAuthentication();
        app.UseAuthorization();
        var isClosed = Configuration.GetValue("Status:Closed", false);

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
        });
    }
 public SecurityHeadersMiddleware(RequestDelegate next, SecurityHeadersPolicy policy)
 {
     _next   = next;
     _policy = policy;
 }
Example #5
0
        public static IApplicationBuilder UseSecurityHeadersMiddleware(this IApplicationBuilder app, SecurityHeadersBuilder builder)
        {
            SecurityHeadersPolicy policy = builder.Build();

            return(app.UseMiddleware <SecurityHeadersMiddleware>(policy));
        }