示例#1
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="configLogic"></param>
        public void Configure(IApplicationBuilder app, IConfigLogic configLogic)
        {
            // Refresh global config
            configLogic.Refresh();

            // Add SecureHeadersMiddleware to the pipeline
            app.UseSecureHeadersMiddleware(_configuration.Get <SecureHeadersMiddlewareConfiguration>());

            app.UseCors("CorsPolicy");

            if (_env.IsDevelopment())
            {
                app.UseDatabaseErrorPage();

                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();

                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });
            }
            else
            {
                app.UseWebMarkupMin();
            }

            // Not necessary for this workshop but useful when running behind kubernetes
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                // Read and use headers coming from reverse proxy: X-Forwarded-For X-Forwarded-Proto
                // This is particularly important so that HttpContent.Request.Scheme will be correct behind a SSL terminating proxy
                ForwardedHeaders = ForwardedHeaders.XForwardedFor |
                                   ForwardedHeaders.XForwardedProto
            });

            app.Use(async(context, next) =>
            {
                await next();

                if (context.Response.IsFailure())
                {
                    context.Request.Path = $"/Error/{context.Response.StatusCode}";
                    await next();
                }
            });


            // Use wwwroot folder as default static path
            app.UseDefaultFiles()
            .UseStaticFiles()
            .UseCookiePolicy()
            .UseSession()
            .UseRouting()
            .UseAuthentication()
            .UseAuthorization()
            .UseEndpoints(endpoints => endpoints.MapControllers());

            Console.WriteLine("Application Started!");
        }
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="configLogic"></param>
        /// <param name="streamRipperManager"></param>
        /// <param name="shoutcastDirectoryApi"></param>
        public void Configure(IApplicationBuilder app, IConfigLogic configLogic, IStreamRipperManager streamRipperManager, IShoutcastDirectoryApi shoutcastDirectoryApi)
        {
            configLogic.Refresh().Wait();

            streamRipperManager.Refresh().Wait();

            shoutcastDirectoryApi.Setup();

            app.UseMiniProfiler();

            app.UseCors("CorsPolicy");

            app.UseResponseCompression();

            if (_env.IsDevelopment())
            {
                app.UseDatabaseErrorPage();

                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();

                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"));
            }

            // Not necessary for this workshop but useful when running behind kubernetes
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                // Read and use headers coming from reverse proxy: X-Forwarded-For X-Forwarded-Proto
                // This is particularly important so that HttpContent.Request.Scheme will be correct behind a SSL terminating proxy
                ForwardedHeaders = ForwardedHeaders.XForwardedFor |
                                   ForwardedHeaders.XForwardedProto
            });

            // Use wwwroot folder as default static path
            app.UseDefaultFiles()
            .UseStaticFiles()
            .UseCookiePolicy()
            .UseSession()
            .UseRouting()
            .UseCors("CorsPolicy")
            .UseAuthentication()
            .UseAuthorization()
            .UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();

                endpoints.MapHub <MessageHub>("/hub");
            });

            Console.WriteLine("Application Started!");
        }
示例#3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IConfigLogic configLogic, IEfRepository repository)
        {
            var dal = repository.For <User>().Session();

            foreach (var user in dal.GetAll().Result)
            {
                user.UserNotifications = new List <UserNotification>
                {
                    new UserNotification
                    {
                        Subject   = "Welcome Back",
                        Text      = "Thanks for coming back to Anahita.dev.",
                        Collected = false,
                        DateTime  = DateTimeOffset.Now
                    }
                };

                dal.Update(user.Id, user).Wait();
            }

            dal.Dispose();

            if (!env.IsDevelopment())
            {
                // Refresh global config
                configLogic.Refresh();
            }

            app.UseResponseCompression();

            if (_env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();

                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();

                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"));
            }
            else
            {
                app.UseWebMarkupMin();
            }

            // Not necessary for this workshop but useful when running behind kubernetes
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                // Read and use headers coming from reverse proxy: X-Forwarded-For X-Forwarded-Proto
                // This is particularly important so that HttpContent.Request.Scheme will be correct behind a SSL terminating proxy
                ForwardedHeaders = ForwardedHeaders.XForwardedFor |
                                   ForwardedHeaders.XForwardedProto
            });

            app.Use(async(context, next) =>
            {
                await next();
                if (context.Response.StatusCode == 404)
                {
                    context.Request.Path = "/error/404";
                    await next();
                }
            });

            // Use wwwroot folder as default static path
            app.UseDefaultFiles()
            .UseStaticFiles()
            .UseCookiePolicy()
            .UseSession()
            .UseRouting()
            .UseCors("CorsPolicy")
            .UseAuthentication()
            .UseAuthorization()
            .UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); });

            Console.WriteLine("Application Started!");
        }