Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager,
                              RoleManager <IdentityRole <int> > roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseMigrationsEndPoint();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // 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.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            IdentityDataInitializer.SeedData(userManager, roleManager);
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Login}/{action=Login}/{id?}");
                endpoints.MapRazorPages();
            });
        }
Exemplo n.º 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, UserManager <User> userManager,
                              RoleManager <Role> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApi v1"));
            }

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

            // FIRST : who are you ?
            app.UseAuthentication();

            // SECOND : are you allowed ?
            app.UseAuthorization();

            IdentityDataInitializer.SeedData(userManager, roleManager);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();
                endpoints.MapControllerRoute(name: "areas", pattern: "{area}/{controller}/{action=Index}/{id?}");
            });
        }
Exemplo n.º 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, UserManager <Person> um)
        {
            EnsureDatabaseCreated <ApplicationDbContext>(app.ApplicationServices);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // 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.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });

            IdentityDataInitializer.SeedData(um);
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, MusicContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // NOTE: Re-enable CORS when deploying
            app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();
            IdentityDataInitializer.SeedData(userManager, roleManager, context);

            DbInitializer.Initialize(context);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var serviceProvider = scope.ServiceProvider;
                var icontext        = serviceProvider.GetRequiredService <IdentityContext>();
                icontext.Database.Migrate();
                try
                {
                    var userManager = serviceProvider.GetRequiredService <UserManager <User> >();

                    var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();

                    IdentityDataInitializer.SeedData(userManager, roleManager);
                }
                catch (Exception ex)
                {
                    var logger = serviceProvider.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                    throw ex;
                }
            }
            host.Run();
        }
Exemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <AccountInfo> userManager, RoleManager <AccountRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseAuthentication();

            app.UseHttpsRedirection();

            app.UseSwagger();



            app.UseSwaggerUI(setupAction =>
            {
                setupAction.SwaggerEndpoint("/swagger/UserServiceOpenApiSpecification/swagger.json", "User Service API");
                setupAction.RoutePrefix = ""; //No /swagger in url
            });

            app.UseRouting();

            app.UseAuthorization();

            // Seeding the identity tables
            IdentityDataInitializer.SeedData(userManager, roleManager);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemplo n.º 7
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 <ApplicationUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            var cultureInfo = new CultureInfo("vi-VN");

            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            IdentityDataInitializer.SeedData(userManager, roleManager);

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

            app.UseAuthentication();
            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemplo n.º 8
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 dbContext, RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(builder => { builder.AllowAnyOrigin(); builder.AllowAnyMethod(); builder.AllowAnyHeader(); });

            //app.UseHttpsRedirection();

            app.UseRouting();

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



            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // ===== Create tables ======
            dbContext.Database.EnsureCreated();

            IdentityDataInitializer.SeedData(roleManager);
        }
Exemplo n.º 9
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 <User> userManager, RoleManager <Role> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseAuthentication();
            app.UseSignalR(routes =>
            {
                routes.MapHub <ChatHub>("/chat");
            });
            IdentityDataInitializer.SeedData(userManager, roleManager).Wait();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemplo n.º 10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseStaticFiles();

            app.UseRouting();



            app.UseSession();

            app.UseAuthentication();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
            IdentityDataInitializer.EnsurePopulated(app);
        }
Exemplo n.º 11
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 <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            Console.WriteLine("seeding");
            IdentityDataInitializer.SeedData(userManager, roleManager);
            IdentityDataInitializer.SeedRoles(roleManager);
            IdentityDataInitializer.SeedUsers(userManager);

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemplo n.º 12
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              UserManager <User> um, RoleManager <IdentityRole> rm)
        {
            app.UseResponseCompression();

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

            if (Configuration.GetDatabaseType() == DatabaseType.InMemory)
            {
                StartupHelper.EnsureDatabaseCreated <MusicalShopIdentityDbContext>(app.ApplicationServices);
            }

            app.UseStaticFiles();
            app.UseClientSideBlazorFiles <Client.Startup>();

            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapFallbackToClientSideBlazor <Client.Startup>("index.html");
            });

            if (env.IsDevelopment())
            {
                IdentityDataInitializer.SeedData(um, rm);
            }
        }
Exemplo n.º 13
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 <ApplicationUser> userManager,
                              RoleManager <ApplicationRole> roleManager, AppDbContext context, ILogger <Startup> logger)
        {
            app.UseCors(x => x
                        .WithOrigins("capacitor://localhost",
                                     "ionic://localhost",
                                     "http://localhost",
                                     "http://localhost:8080",
                                     "http://localhost:8100",
                                     "http://localhost:8000",
                                     //"*",
                                     "https://falcim.xyz",
                                     "http://falcim.xyz",
                                     "https://www.falcim.xyz",
                                     "http://www.falcim.xyz"
                                     )
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        //.AllowCredentials()
                        .SetIsOriginAllowed(hostName => true));

            //For 204 errors
            //app.Use(async (ctx, next) =>
            //{
            //    await next();
            //    if(ctx.Response.StatusCode == 204)
            //    {
            //        ctx.Response.ContentLength = 0;
            //    }
            //});

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

            app.ConfigureExceptionHandler(logger);

            //var url = Configuration["ApplicationSettings:JWT_Secret"].ToString();

            app.UseAuthentication();

            if (Configuration.GetValue <bool>("InitializeSampleData"))
            {
                IdentityDataInitializer.SeedData(userManager, roleManager, context);
            }

            app.UseMvc();

            app.UseFileServer(new FileServerOptions
            {
                FileProvider            = new PhysicalFileProvider(Path.Combine(env.ContentRootPath + "/", Configuration.GetValue <string>("FileServerRequestPath"))),
                RequestPath             = "/Assets",
                EnableDirectoryBrowsing = false
            });
        }
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     WorldCupDatabaseInitializer.InitDb();
     IdentityDataInitializer.InitDbIdentity();
 }
Exemplo n.º 15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager, RoleManager <Role> roleManager, MongoDatabaseService mongoDatabaseService)
        {
            new MongoDataInitializer(mongoDatabaseService).SeedData();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // 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.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

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

            app.UseRouting();

            app.UseCors("AllowAll");

            app.UseAuthentication();
            IdentityDataInitializer.SeedData(userManager, roleManager);
            app.UseAuthorization();

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

            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");
                }
            });
        }
Exemplo n.º 16
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, IAppConfigManager appConfigManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

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

            app.UseAuthentication();

            // Seed a sample User and role
            IdentityDataInitializer.SeedData(userManager, roleManager, appConfigManager);


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


            // Localization: Here we are building a list of supported cultures which will be used in
            //               the RequestLocalizationOptions in the app.UseRequestLocalization call below.
            var supportedCultures = new[]
            {
                new CultureInfo("en-US"),
                new CultureInfo("es-MX"),
                new CultureInfo("fr-FR"),
            };

            // Localization: Here we are configuring the RequstLocalization including setting the supported cultures from above
            //               in the RequestLocalizationOptions. We are also setting the default request culture to be used
            //               for current culture. These options will be used wherever we request localized strings.
            //               For more information see https://docs.asp.net/en/latest/fundamentals/localization.html
            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en-US"),

                // Formatting numbers, dates, etc.
                SupportedCultures = supportedCultures,

                // UI strings that we have localized.
                SupportedUICultures = supportedCultures
            });
        }
Exemplo n.º 17
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 <AppUser> userManager,
            RoleManager <AppRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseExceptionHandler(
                builder =>
            {
                builder.Run(
                    async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                    var error = context.Features.Get <IExceptionHandlerFeature>();
                    if (error != null)
                    {
                        context.Response.AddApplicationError(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);
                    }
                });
            });

            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseAuthentication();

            // Seed default admin user and roles
            IdentityDataInitializer.SeedData(userManager, roleManager);

            // 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", "WebApi Browler V1");
            });

            app.UseMvc();
        }
Exemplo n.º 18
0
 public AccountController(
     AspNetUserManager <User> userManager,
     SignInManager <User> signInManager,
     RoleManager <Role> roleManager,
     IOptions <AppSettings> appSettings,
     ILogger <AccountController> logger
     ) : base(appSettings, logger)
 {
     _signInManager = signInManager;
     _userManager   = userManager;
     _roleManager   = roleManager;
     IdentityDataInitializer.SeedData(_userManager, _roleManager);
 }
Exemplo n.º 19
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 <VehicleTrackingUser> userManager,
                              RoleManager <IdentityRole <Guid> > roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseAuthentication();
            app.UseMiddleware <ExceptionHandlerMiddleware>();
            IdentityDataInitializer.SeedData(userManager, roleManager).Wait();
            app.UseMvc();
        }
Exemplo n.º 20
0
        public void SeedDataSuccessRoleAdded()
        {
            _userManagerMock.Setup(x => x.CreateAsync(It.Is <Role>(x => x.Name == nameof(UserTypeEnum.Participant) ||
                                                                   x.Name == nameof(UserTypeEnum.Reviewer))))
            .ReturnsAsync(IdentityResult.Success);

            var err = Record.Exception(() => IdentityDataInitializer.SeedData(_userManagerMock.Object));

            err.Should().BeNull();

            _userManagerMock.Verify(x => x.CreateAsync(It.Is <Role>(x => x.Name == nameof(UserTypeEnum.Participant) ||
                                                                    x.Name == nameof(UserTypeEnum.Reviewer))),
                                    Times.Exactly(2));
        }
Exemplo n.º 21
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, InsurerDbContext context,
                              UserManager <ApplicationUser> _userManager, RoleManager <IdentityRole> _roleManager)
        {
            if (env.IsDevelopment())
            {
                // When the app runs in the Development environment:
                //   Use the Developer Exception Page to report app runtime errors.
                //   Use the Database Error Page to report database runtime errors.
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                app.UseBrowserLink();
            }
            else
            {
                // When the app doesn't run in the Development environment:
                //   Enable the Exception Handler Middleware to catch exceptions
                //     thrown in the following middlewares.
                app.UseExceptionHandler("/Home/Error");
            }

            // Return static files and end the pipeline.
            // Static files not compressed by Static File Middleware.
            app.UseStaticFiles();

            // Use Cookie Policy Middleware to conform to EU General Data
            // Protection Regulation (GDPR) regulations.
            app.UseCookiePolicy();

            //  Response Compression Middleware
            app.UseResponseCompression();

            // Authenticate before the user accesses secure resources.
            app.UseAuthentication();

            IdentityDataInitializer.SeedData(_userManager, _roleManager);

            // If the app uses session state, call Session Middleware after Cookie
            // Policy Middleware and before MVC Middleware.
            app.UseSession();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
            // Add MVC to the request pipeline.
            app.UseMvcWithDefaultRoute();

            //  Initialise the database with sample data
            //DbInitializer.Initialize(context);    -- Commented by Levi Nkata - 02/05/2019
        }
Exemplo n.º 22
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 dataContext,
                              UserManager <AppUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "SkillShareApi v1"));
            }

            app.UseExceptionHandler(
                builder =>
            {
                builder.Run(
                    async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                    var error = context.Features.Get <IExceptionHandlerFeature>();
                    if (error != null)
                    {
                        context.Response.AddApplicationError(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);
                    }
                });
            });

            //app.UseHttpsRedirection();
            // migrate any database changes on startup (includes initial db creation)
            dataContext.Database.Migrate();

            app.UseRouting();

            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseAuthentication();

            IdentityDataInitializer.SeedData(userManager);

            app.UseAuthorization();

            app.UseEndpoints(endpoints => endpoints.MapControllers());
        }
Exemplo n.º 23
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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/errors/500");

                // 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.UseCors();
            app.UseStatusCodePagesWithReExecute("/errors/{0}");
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();
            app.UseAuthentication();

            // Seed roles and users for testing on development and staging environment.
            if (!env.IsProduction())
            {
                IdentityDataInitializer.SeedData(userManager, roleManager, Configuration);
            }

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

            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");
                }
            });
        }
Exemplo n.º 24
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("init main");
                var host = BuildWebHost(args);
                using (var scope = host.Services.CreateScope())
                {
                    var serviceProvider = scope.ServiceProvider;
                    try
                    {
                        var userManager     = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                        var roleManager     = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                        var operatorManager = serviceProvider.GetRequiredService <IOperatorManager>();
                        var codeManager     = serviceProvider.GetRequiredService <ICodeManager>();
                        var tariffManager   = serviceProvider.GetRequiredService <ITariffManager>();
                        var stopWordManager = serviceProvider.GetRequiredService <IStopWordManager>();
                        var unitOfWork      = serviceProvider.GetRequiredService <IUnitOfWork>();

                        IdentityDataInitializer.SeedData(userManager, roleManager, operatorManager, codeManager, tariffManager, stopWordManager, unitOfWork);

                        // Start Notification scheduler

                        NotificationScheduler.Start(scope.ServiceProvider);
                        MailingScheduler.Start(scope.ServiceProvider);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Stopped program because of exception");
                    }
                }
                host.Run();
            }
            catch (Exception ex)
            {
                //NLog: catch setup errors
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
                NLog.LogManager.Shutdown();
            }
        }
Exemplo n.º 25
0
 private static async Task SeedData(IWebHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var _userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
             var _roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
             await IdentityDataInitializer.SeedDataAsync(_userManager, _roleManager);
         }
         catch (Exception ex)
         {
             var logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(ex, "An error occurred while seeding the database.");
         }
     }
 }
Exemplo n.º 26
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var serviceProvider = scope.ServiceProvider;
                try
                {
                    IdentityDataInitializer.SeedData(serviceProvider);
                }
                catch (Exception)
                {
                }
            }

            host.Run();
        }
Exemplo n.º 27
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            UserManager <User> userManager,
            RoleManager <Role> roleManager)
        {
            app.UseExceptionHandler("/api/error");

            app.UseHttpsRedirection();

            // Needed for hosting in Azure Web App
            var forwardOptions = new ForwardedHeadersOptions
            {
                ForwardedHeaders      = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
                RequireHeaderSymmetry = false
            };

            forwardOptions.KnownNetworks.Clear();
            forwardOptions.KnownProxies.Clear();
            app.UseForwardedHeaders(forwardOptions);

            app.UseRouting();

            app.UseIdentityServer();

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

            // Seed default Roles and Users
            IdentityDataInitializer.SeedDataAsync(userManager, roleManager, _configuration).Wait();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Caff Store API v1");

                options.OAuthClientId("swagger");
                options.DisplayOperationId();
            });
        }
Exemplo n.º 28
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 <User> userManager, RoleManager <Role> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(setup => setup.SwaggerEndpoint("/swagger/v1/swagger.json", "LearnWithMentor API"));
            }
            else
            {
                app.UseHsts();
            }

            app.UseAuthentication();
            IdentityDataInitializer.SeedData(userManager, roleManager).Wait();
            app.UseCors(Constants.Cors.policyName);
            app.UseSignalR(routes => routes.MapHub <NotificationController>("/api/notifications"));
            app.UseHttpsRedirection();
            app.UseMvc();
        }
Exemplo n.º 29
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env
                              , UserManager <User> userManager,
                              RoleManager <Role> roleManager,
                              IRoleDatabaseService roleDbService, IUserDatabaseService userDatabaseService
                              , IPartnersDatabaseService partnersDatabase
                              , IBrandsDatabaseService brandsDatabaseService
                              , ICategoryDatabaseService categoryDatabaseService
                              , IStatusDatabaseService statusDatabaseService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // 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.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();
            app.UseSession();

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

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


            IdentityDataInitializer.SeedData(userManager, roleManager, roleDbService, userDatabaseService, partnersDatabase, brandsDatabaseService, categoryDatabaseService, statusDatabaseService).Wait();
        }
Exemplo n.º 30
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {
            app.UseExceptionHandler(
                builder =>
            {
                builder.Run(
                    async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                    var error = context.Features.Get <IExceptionHandlerFeature>();
                    if (error != null)
                    {
                        context.Response.AddApplicationError(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);
                    }
                });
            });

            app.UseDefaultFiles();
            app.UseStaticFiles();

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

            app.UseCors(builder => builder.WithOrigins("http://localhost:4200"));

            app.UseSwagger();
            app.UseAuthentication();
            app.UseMvc();

            IdentityDataInitializer.SeedData(serviceProvider);
            app.Run(context => {
                context.Response.Redirect("../swagger");
                return(Task.CompletedTask);
            });
        }