コード例 #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, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            // Seed identity database with admin role & account
            IdentityInitializer.SeedRoles(roleManager);
            IdentityInitializer.SeedAdminUser(userManager);

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

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

            app.UseAuthentication();

            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
コード例 #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,
            ApplicationDbContext context,
            IdentityInitializer identityInitializer)
        {
            context.Database.EnsureCreated();

            app.UseExceptionHandler(errorApp =>
                                    errorApp.Run(async context =>
            {
                context.Response.ContentType    = "text/Plain";
                var exceptionHandlerPathFeature =
                    context.Features.Get <IExceptionHandlerPathFeature>();
                if (exceptionHandlerPathFeature?.Error is EntityAlreadyExistsException)
                {
                    context.Response.StatusCode = 409;
                    await context.Response.WriteAsync("Enity already exsist!");
                }
                else if (exceptionHandlerPathFeature?.Error is EntityNotFoundException)
                {
                    context.Response.StatusCode = 404;
                    await context.Response.WriteAsync("Enity not found!");
                }
                else
                {
                    context.Response.StatusCode = 400;
                    await context.Response.WriteAsync("Oops, something bad happened!");
                }
            }));

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            app.UseAuthentication();
            app.UseIdentityServer();
            app.UseAuthorization();

            identityInitializer.SeedAdminUser();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                    //spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
                }
            });
        }