示例#1
0
        private void SetDefaultUser(CeresisUserManager userManager)
        {
            var admin = userManager.FindByNameAsync("admin").Result;

            if (admin == null)
            {
                admin = new User
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };
                var resultUser = userManager.CreateAsync(admin, "XS4wpBtUZj").Result;

                if (resultUser.Succeeded)
                {
                    var token = userManager.GenerateEmailConfirmationTokenAsync(admin).Result;
                    resultUser = userManager.ConfirmEmailAsync(admin, token).Result;
                    var resultRole = userManager.AddToRoleAsync(admin, "admin").Result;
                }
            }
        }
示例#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, DatabaseContext repositoryContext, CeresisUserManager userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseForwardedHeaders(new ForwardedHeadersOptions()
            {
                ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.All
            });

            if (!repositoryContext.Database.GetPendingMigrations().IsEmpty())
            {
                repositoryContext.Database.Migrate();
            }

            app.UseStaticFiles();

            if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "workplace")))
            {
                Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "workplace"));
            }

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

            app.UseDirectoryBrowser(new DirectoryBrowserOptions
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "workplace")),
                RequestPath = "/workplace"
            });

            if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "catalog")))
            {
                Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "catalog"));
            }

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

            app.UseDirectoryBrowser(new DirectoryBrowserOptions
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "catalog")),
                RequestPath = "/catalog"
            });

            app.UseSwagger();

            SetDefaultUser(userManager);

            app.UseAuthentication();

            app.UseMiddleware <CustomExceptionHandler>();

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

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