Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app,
                                    IHostingEnvironment env,
                                    ILoggerFactory loggerFactory,
                                    IIdentitySeed storageSeed,
                                    IMasterDataCacheOperations masterDataCacheOperations,
                                    ILogDataOperations logDataOperations,
                                    INavigationCacheOperations navigationCacheOperations)
        {
            loggerFactory.AddConsole();
            // Configure Azure Logger to log all events except the one which are generated by default by ASP.NET Core.
            loggerFactory.AddAzureTableStorageLog(logDataOperations,
                                                  (categoryName, logLevel) => !categoryName.Contains("Microsoft") && logLevel >= LogLevel.Information);

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

            var options = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >();

            app.UseRequestLocalization(options.Value);

            app.UseStatusCodePagesWithRedirects("/Home/Error/{0}");
            app.UseSession();
            app.UseStaticFiles();
            app.UseIdentity();

            app.UseGoogleAuthentication(new GoogleOptions()
            {
                ClientId     = Configuration["Google:Identity:ClientId"],
                ClientSecret = Configuration["Google:Identity:ClientSecret"]
            });

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

            app.UseWebSockets();
            app.UseSignalR();

            await storageSeed.Seed(app.ApplicationServices.GetService <UserManager <ApplicationUser> >(),
                                   app.ApplicationServices.GetService <RoleManager <IdentityRole> >(),
                                   app.ApplicationServices.GetService <IOptions <ApplicationSettings> >());

            await masterDataCacheOperations.CreateMasterDataCacheAsync();

            await navigationCacheOperations.CreateNavigationCacheAsync();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app,
                                    IHostingEnvironment env,
                                    ILoggerFactory loggerFactory,
                                    IIdentitySeed storageSeed,
                                    IMasterDataCacheOperations masterDataCacheOperations,
                                    ILogDataOperations logDataOperations,
                                    INavigationCacheOperations navigationCacheOperations,
                                    IUnitOfWork unitOfWork)
        {
            loggerFactory.AddConsole();
            // Configure Azure Logger to log all events except the one which are generated by default by ASP.NET Core.
            loggerFactory.AddAzureTableStorageLog(logDataOperations,
                                                  (categoryName, logLevel) => !categoryName.Contains("Microsoft") && logLevel >= LogLevel.Information);

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

            var options = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >();

            app.UseRequestLocalization(options.Value);

            app.UseStatusCodePagesWithRedirects("/Home/Error/{0}");
            app.UseSession();
            app.UseStaticFiles();
            app.UseIdentity();

            app.UseGoogleAuthentication(new GoogleOptions()
            {
                ClientId     = Configuration["Google:Identity:ClientId"],
                ClientSecret = Configuration["Google:Identity:ClientSecret"]
            });

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

            app.UseWebSockets();
            app.UseSignalR();

            await storageSeed.Seed(app.ApplicationServices.GetService <UserManager <ApplicationUser> >(),
                                   app.ApplicationServices.GetService <RoleManager <IdentityRole> >(),
                                   app.ApplicationServices.GetService <IOptions <ApplicationSettings> >());

            var models = Assembly.Load(new AssemblyName("ASC.Models")).GetTypes().Where(type => type.Namespace == "ASC.Models.Models");

            foreach (var model in models)
            {
                var        repositoryInstance = Activator.CreateInstance(typeof(Repository <>).MakeGenericType(model), unitOfWork);
                MethodInfo method             = typeof(Repository <>).MakeGenericType(model).GetMethod("CreateTableAsync");
                method.Invoke(repositoryInstance, new object[0]);
            }

            await masterDataCacheOperations.CreateMasterDataCacheAsync();

            await navigationCacheOperations.CreateNavigationCacheAsync();
        }
Пример #3
0
 /// <summary>
 ///     Default constructor.
 /// </summary>
 public IdentitySecurity(SignInManager <User> signInManager, IIdentitySeed seed = null)
 {
     _signInManager = signInManager;
     _seed          = seed;
 }
Пример #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, ApplicationDbContext ctx, IIdentitySeed identitySeed, IRoleSeed roleSeed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }

            // To get access to the wwwroot files:
            app.UseStaticFiles();
            app.UseAuthentication();
            app.UseMvcWithDefaultRoute();
            app.UseSession();

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

                routes.MapRoute(
                    name: "details",
                    template: "{controller=Product}/{action=Details}/{id?}");
            });

            var runIdentitySeed = Task.Run(async() => await identitySeed.CreateAdminAccountIfEmpty()).Result;
            var runRoleSeed     = Task.Run(async() => await roleSeed.CreateRoleIfEmpty()).Result;

            //Seed.FillIfEmpty(ctx);
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                                    IIdentitySeed storageSeed,
                                    ILogDataOperations logDataOperations, IUnitOfWork unitOfWork,
                                    INavigationCacheOperations navigationCacheOperations
                                    )
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            // Configure Azure Logger to log all events except the ones that are generated by default by ASP.NET Core.
            loggerFactory.AddAzureTableStorageLog(logDataOperations, (categoryName, logLevel) => !categoryName.Contains("Microsoft") &&
                                                  logLevel >= LogLevel.Information);

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

            app.UseStatusCodePagesWithRedirects("/Home/Error/{0}");
            app.UseSession();
            app.UseStaticFiles();

            app.UseAuthentication();

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



            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "areaRoute",
                                template: "{area:exists}/{controller=Home}/{action=Index}");

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

            using (var scope = app.ApplicationServices.CreateScope())
            {
                //Resolve ASP .NET Core Identity with DI help
                var userManager = (UserManager <ApplicationUser>)scope.ServiceProvider.GetService(typeof(UserManager <ApplicationUser>));
                var roleManager = (RoleManager <ApplicationRole>)scope.ServiceProvider.GetService(typeof(RoleManager <ApplicationRole>));
                var options     = (IOptions <ApplicationSettings>)scope.ServiceProvider.GetService(typeof(IOptions <ApplicationSettings>));

                await storageSeed.Seed(userManager, roleManager, options);

                // do you things here
            }

            var models = Assembly.Load(new AssemblyName("ASC.Models")).GetTypes().Where(type => type.Namespace == "ASC.Models.Models");

            foreach (var model in models)
            {
                var        repositoryInstance = Activator.CreateInstance(typeof(Repository <>).MakeGenericType(model), unitOfWork);
                MethodInfo method             = typeof(Repository <>).MakeGenericType(model).GetMethod("CreateTableAsync");
                method.Invoke(repositoryInstance, new object[0]);
            }


            //await masterDataCacheOperations.CreateMasterDataCacheAsync();
            await navigationCacheOperations.CreateNavigationCacheAsync();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ILoggerFactory loggerFactory,
            IIdentitySeed storageSeed,
            IMasterDataCacheOperations masterDataCacheOperations,
            ILogDataOperations logDataOperations,
            INavigationCacheOperations navigationCacheOperations,
            IUnitOfWork unitOfWork)
        {
            // Configure Azure Logger to log all events except the ones that are generated by default by ASP.NET Core.
            loggerFactory.AddAzureTableStorageLog(logDataOperations, (categoryName, logLevel) => !categoryName.Contains("Microsoft") && logLevel >= LogLevel.Information);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            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.UseStatusCodePagesWithRedirects("/Home/Error/{0}");

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

            app.UseRouting();

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

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

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

                endpoints.MapRazorPages();
            });

            //Create a scope to resolve dependencies registered as scoped
            using (var scope = app.ApplicationServices.CreateScope())
            {
                //Resolve ASP .NET Core Identity with DI help
                var userManager = (UserManager <ApplicationUser>)scope.ServiceProvider.GetService(typeof(UserManager <ApplicationUser>));
                var roleManager = (RoleManager <IdentityRole>)scope.ServiceProvider.GetService(typeof(RoleManager <IdentityRole>));
                var options     = (IOptions <ApplicationSettings>)scope.ServiceProvider.GetService(typeof(IOptions <ApplicationSettings>));

                // do you things here
                await storageSeed.Seed(userManager, roleManager, options);
            }

            var models = Assembly.Load(new AssemblyName("ASC.Models")).GetTypes().Where(type => type.Namespace == "ASC.Models.Models");

            foreach (var model in models)
            {
                var repositoryInstance = Activator.CreateInstance(typeof(Repository <>).
                                                                  MakeGenericType(model), unitOfWork);
                MethodInfo method = typeof(Repository <>).MakeGenericType(model).GetMethod("CreateTableAsync");
                method.Invoke(repositoryInstance, new object[0]);
            }

            await masterDataCacheOperations.CreateMasterDataCacheAsync();

            await navigationCacheOperations.CreateNavigationCacheAsync();
        }