示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            ServiceMapperConfig.Config();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            app.UseAuthentication();

            app.UseCors(builder =>
            {
                // Matches the url and port coming from app-admin
                // TODO: Review AllowCredntials
                // https://docs.microsoft.com/en-us/aspnet/core/security/cors#credentials-in-cross-origin-requests#credentials-in-cross-origin-requests
                builder.WithOrigins("http://localhost:4200")
                .AllowCredentials();
            });

            ConfigureMvc(app);
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            ServiceMapperConfig.Config();

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor |
                                   ForwardedHeaders.XForwardedProto
            });
            app.UseAuthentication();
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areas",
                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute("login", "login",
                                defaults: new { controller = "Account", action = "Login" });
                routes.MapRoute("register", "register",
                                defaults: new { controller = "Account", action = "Register" });
                routes.MapRoute("lastnews", "lastnews",
                                defaults: new { controller = "Post", action = "LastNews" });
                routes.MapRoute("post", "post/{id}",
                                defaults: new { controller = "Post", action = "Index" });
                routes.MapRoute("blog", "blog/page/{id}",
                                defaults: new { controller = "Blog", action = "Page" });
                routes.MapRoute("category", "category/{url}",
                                defaults: new { controller = "Category", action = "Index" });
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            ServiceMapperConfig.Config();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            app.UseAuthentication();

            ConfigureMvc(app);
        }
示例#4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            ServiceMapperConfig.Config();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseAuthentication();
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            ConfigureCors(app);
            ConfigureSwagger(app);
            ConfigureMvc(app);
        }
示例#5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseStaticFiles(new StaticFileOptions()
            {
                OnPrepareResponse = c =>
                {
                    //Do not add cache to json files. We need to have new versions when we add new translations.

                    c.Context.Response.GetTypedHeaders().CacheControl = !c.Context.Request.Path.Value.Contains(".json")
            ? new CacheControlHeaderValue()
                    {
                        MaxAge = TimeSpan.FromDays(30) // Cache everything except json for 30 days
                    }
            : new CacheControlHeaderValue()
                    {
                        MaxAge = TimeSpan.FromMinutes(15) // Cache json for 15 minutes
                    };
                }
            });


            app.UseDeveloperExceptionPage();



            ServiceMapperConfig.Config();
            app.UseAuthentication();
            if (env.IsDevelopment())
            {
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement         = true,
                    HotModuleReplacementEndpoint = "/dist/__webpack_hmr"
                });
                TelemetryConfiguration.Active.DisableTelemetry = true;
            }
            else
            {
                app.UseHsts();
            }


            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseRobotify();
            app.UseHttpsRedirection();
            app.UseCookiePolicy();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapRoute(
                    "Sitemap",
                    "sitemap.xml",
                    new { controller = "Home", action = "Sitemap" });

                routes.MapRoute(
                    "feed",
                    "rssfeed.xml",
                    new { controller = "Home", action = "RSSFeed" });

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
            app.UseExceptionHandler("/Home/Error");
        }