Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // 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.UseMvc();

            PlusStarter.Create <BlogWebModule>(options =>
            {
                options.IocManager
                .IocContainer
                .AddFacility <LoggingFacility>(x => x.UseLog4Net()
                                               .WithConfig("log4net.config"));
            }).Initialize();
        }
Пример #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));

            services.AddResponseCaching();

            services.AddRouting(options =>
            {
                options.LowercaseUrls       = true;
                options.AppendTrailingSlash = true;
            });

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

            services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, x =>
            {
                x.LoginPath = "/account/auth";
            });

            services.AddSession();
            services.AddHttpClient();

            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
                options.Filters.Add(new AuthorizeFilter(policy));

                options.Filters.Add <ActionParameterValidateAttribute>();
                options.Filters.Add <GlobalExceptionFilter>();

                options.CacheProfiles.Add("default", new CacheProfile {
                    Duration = 60
                });
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSwaggerGen(options =>
            {
                var basePath = Directory.GetCurrentDirectory();
                var info     = new Info
                {
                    Version     = "v3.0.x",
                    Title       = "阿星Plus - 个人博客以及通用数据接口",
                    Description = @"框架:<code>.NET Core 2.2</code>、<a href='https://github.com/Meowv/.netcoreplus'>.netcoreplus</a>
                                    博客:https://meowv.com
                                    开源:https://github.com/Meowv/Blog"
                };
                options.SwaggerDoc("v1", info);
                options.DocumentFilter <TagDescriptionsFilter>();
                options.IncludeXmlComments(Path.Combine(basePath, "MeowvBlog.Core.xml"));
                options.IncludeXmlComments(Path.Combine(basePath, "MeowvBlog.Services.Dto.xml"));
                options.IncludeXmlComments(Path.Combine(basePath, "MeowvBlog.Web.xml"));
            });

            PlusStarter.Create <MeowvBlogWebModule>(options =>
            {
                options.IocManager
                .IocContainer
                .AddFacility <LoggingFacility>(x => x.UseLog4Net()
                                               .WithConfig("log4net.config"));
            }).Initialize();
        }