Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            //Compres response with GZipCompression
            services.AddResponseCompression();

            // Add framework services.
            services.AddMvc();

            services.AddAuthentication("cookietronauth").AddCookie("cookietronauth", options =>
            {
                options.LoginPath         = new PathString("/Account/Login/");
                options.AccessDeniedPath  = new PathString("/Account/Login/");
                options.SlidingExpiration = true;
                options.ExpireTimeSpan    = new System.TimeSpan(12, 0, 0);
            });

            //authorization
            services.AddAuthorization(options =>
            {
                options.AddPolicy("LoggedIn",
                                  policy => policy.Requirements.Add(new CookieAuthorize()));
            });
            services.AddScoped <IAuthorizationHandler, CookieAuthorizeHandler>();

            //localization
            services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
            services.Configure <RequestLocalizationOptions>(
                opts =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo("bg")
                };

                opts.DefaultRequestCulture = new RequestCulture(culture: "bg", uiCulture: "bg");
                // Formatting numbers, dates, etc.
                opts.SupportedCultures = supportedCultures;
                // UI strings that we have localized.
                opts.SupportedUICultures = supportedCultures;
            });

            services.Configure <IISOptions>(options =>
            {
            });

            DependencyConfiguration dependencyConfiguration = new DependencyConfiguration();

            dependencyConfiguration.AddDependencies(services, Configuration);
        }