Example #1
0
        public static Container Configure(Container container)
        {
            CommonBootstrapper.Configure(container);
            InfrastructureBootstrapper.Configure(container);
            ServiceBootstrapper.Configure(container);

            return(container);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            var connectionString = Configuration.GetConnectionString("NavidGhavami_PersonalWebsite");



            PersonalInformationBootstrapper.Configure(services, connectionString);
            BlogManagementBootstrapper.Configure(services, connectionString);
            ProjectBootstrapper.Configure(services, connectionString);
            ServiceBootstrapper.Configure(services, connectionString);
            AccountManagementBootstrapper.Configure(services, connectionString);



            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.Arabic));


            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddTransient <IFileUploader, FileUploader>();
            services.AddTransient <IAuthHelper, AuthHelper>();


            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.Lax;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account");
                o.LogoutPath       = new PathString("/Account");
                o.AccessDeniedPath = new PathString("/AccessDenied");
            });



            services.AddAuthorization(options =>
            {
                options.AddPolicy("AdminArea",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator, Roles.ContentUploader
                }));

                options.AddPolicy("PersonalInformation",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Projects",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Services",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));

                options.AddPolicy("Account",
                                  builder => builder.RequireRole(new List <string> {
                    Roles.Administrator
                }));
            });

            services.AddRazorPages()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Administration", "/", "AdminArea");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Accounts", "Account");
                options.Conventions.AuthorizeAreaFolder("Administration", "/PersonalInformation", "PersonalInformation");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Projects", "Projects");
                options.Conventions.AuthorizeAreaFolder("Administration", "/Services", "Services");
            });
        }