Пример #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, SeedUsersAndRoles seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseExceptionHandler(builder => {
                    builder.Run(async context => {
                        context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                        context.Response.ContentType = "application/json";

                        var contextFeatures = context.Features.Get <IExceptionHandlerFeature>();

                        if (context != null)
                        {
                            context.Response.Headers.Add("Application-Error", contextFeatures.Error.Message);
                            context.Response.Headers.Add("Access-Control-Expose-Headers", "Application-Error");
                            context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                            await context.Response.WriteAsync(JsonConvert.SerializeObject(contextFeatures.Error.Message));
                        }
                    });
                });
                //app.UseHsts();
            }

            seed.BeginSeeding();
            //app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseMvc();
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SeedUsersAndRoles seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(builder => {
                    builder.Run(async context => {
                        context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                        context.Response.ContentType = "application/json";

                        var contextFeatures = context.Features.Get <IExceptionHandlerFeature>();

                        if (context != null)
                        {
                            context.Response.Headers.Add("Application-Error", contextFeatures.Error.Message);
                            context.Response.Headers.Add("Access-Control-Expose-Headers", "Application-Error");
                            context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                            await context.Response.WriteAsync(JsonConvert.SerializeObject(contextFeatures.Error.Message));
                        }
                    });
                });
            }

            seed.BeginSeeding();

            app.UseAuthentication();
            app.UseCors(opt =>
                        opt.AllowAnyOrigin()
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        );

            //app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(name: "default", pattern: "api/{controller}/{action}");
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, SeedUsersAndRoles seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.ConfigureGlobalExceptionHandler();
                //app.UseHsts();
            }

            seed.BeginSeeding();
            //app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseCors(opt => opt.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            app.UseMvc();
        }
Пример #4
0
        public void Configure(IApplicationBuilder app, FiscalContext context, ILogger <Startup> logger, UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager, SignInManager <AppUser> signInManager, IWebHostEnvironment environment)
        {
            //context.Database.EnsureDeleted();
            if (context.Database.EnsureCreated())
            {
                SeedUsersAndRoles.CreateInitialUsers(userManager, roleManager, signInManager);
            }

            app.UseStaticFiles();

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(environment.ContentRootPath, "node_modules")),
                RequestPath  = "/node_modules"
            });

            app.UseNodeModules();

            //app.UseCookiePolicy();
            app.UseSession();

            app.UseCors();

            app.UseAuthentication();

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

            app.UseSignalR(hubRootBuilder => {
                hubRootBuilder.MapHub <ChatHub>("/chathub");
            });

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #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, SeedUsersAndRoles seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                //app.UseHsts();
                app.UseGlobalExceptionHandler();
            }

            seed.BeginSeeding();
            //app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseCors(opt => opt.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            app.UseMvc();
        }
Пример #6
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ChatContext _context, UserManager <ChatUser> userManager, RoleManager <IdentityRole> roleManager, SignInManager <ChatUser> signInManager)
        {
            _context.Database.EnsureDeleted();
            if (_context.Database.EnsureCreated())
            {
                SeedUsersAndRoles.CreateInitialUsers(userManager, roleManager, signInManager);
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors("FromClient");

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                endpoints.MapHub <ChatHub>("/chathub");
                endpoints.MapControllers();
            });
        }
Пример #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, SiteContext dbcontext, IWebHostEnvironment env, ILogger <Startup> logger, UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            logger.LogInformation($"Work environment is: {env.EnvironmentName}");

            app.UseCors();

            app.UseSession();

            //app.UseCors(p => {
            //    p.WithOrigins("https://www.google.com");
            //});

            if (env.IsDevelopment())
            {
                dbcontext.Database.EnsureDeleted();
                dbcontext.Database.EnsureCreated();
                SeedUsersAndRoles.CreateInitialUsers(userManager, roleManager);
            }
            else
            {
                dbcontext.Database.EnsureCreated();
            }

            app.UseAuthentication();

            app.UseStatusCodePages();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/error");
            }

            app.UseStaticFiles(new StaticFileOptions()
            {
                RequestPath = "/wwwroot"
            });

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "StaticFolder")),
                RequestPath  = "/staticfolder"
            });

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "node_modules")),
                RequestPath  = "/node_modules"
            });

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(a =>
                             a.MapDefaultControllerRoute());

            //app.Run(async (context) => {
            //    await Task.Run(() => context.Response.StatusCode = 500);
            //});

            //app.Run(async (context) => {
            //    await Task.Run(() => throw new NotImplementedException());
            //});

            app.Run(async(context) => {
                string response = "This is response!!!";
                await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes(response));
            });
        }
Пример #8
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ShopContext _dbcontext, UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            //_dbcontext.Database.EnsureDeleted();
            if (_dbcontext.Database.EnsureCreated())
            {
                SeedUsersAndRoles.CreateInitialUsers(userManager, roleManager);
            }

            app.UseStatusCodePages();

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

            app.UseSession();

            app.UseCors("FromGoogle");

            app.UseStaticFiles();

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "node_modules")),
                RequestPath  = "/node_modules"
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSignalR(route => {
                route.MapHub <ChatHub>("/chathub");
            });

            app.UseAuthentication();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                //endpoints.MapHub<ChatHub>("/chathub");

                //endpoints.MapControllerRoute(
                //    name: "AreaRoute",
                //    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
                //    );

                endpoints.MapAreaControllerRoute(
                    name: "FirstArea",
                    areaName: "FirstArea",
                    pattern: "First/{controller=Home}/{action=Index}/{id?}"
                    );

                endpoints.MapAreaControllerRoute(
                    name: "SecondArea",
                    areaName: "SecondArea",
                    pattern: "Second/{controller=Home}/{action=Index}/{id?}"
                    );


                endpoints.MapControllerRoute(
                    name: "Default",
                    pattern: "{controller=Home}/{action=Index}/{id?}",
                    dataTokens: new { locale = "route with int id" }
                    );
            });
        }