Esempio n. 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();
            }

            #region AutoMapper配置项
            AutoMapperStartup.Register();//加载AutoMapper配置项
            #endregion



            //使用跨域
            app.UseCors("AllowAllOrigin");

            // 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(i =>
            {
                i.SwaggerEndpoint("/swagger/v1/swagger.json", "CoreSolution API V1");
                i.ShowExtensions();
            });

            app.UseMvc();
        }
Esempio n. 2
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
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = new FileExtensionContentTypeProvider
                {
                    Mappings =
                    {
                        new KeyValuePair <string, string>(".moc", ""),
                        new KeyValuePair <string, string>(".mtn", "")
                    }
                }
            });
            app.UseCookiePolicy();

            AutoMapperStartup.Register();//加载AutoMapper配置项

            app.UseAuthentication();

            app.UseSignalR(routes =>
            {
                routes.MapHub <ChatHub>("/chatHub");
            });

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

                routes.MapRoute(
                    name: "live2d",
                    template: "{controller}",
                    defaults: "live2d/model.moc"
                    );
            });
        }
Esempio n. 3
0
        public void Configuration(IAppBuilder app)
        {
            NinjectHttpContainer.RegisterModules(NinjectHttpModules.Modules);
            ApplicationUserManager.SetDataProtectionProvider(app.GetDataProtectionProvider());

            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(() => new DataAccessContext());
            app.CreatePerOwinContext(() =>
            {
                var context   = new DataAccessContext();
                var userStore = new UserStore <User, Role, Guid, UserLogin, UserRole, Claim>(context);

                return(new ApplicationUserManager(userStore));
            });

            //Authentication configuration
            var authConfig = NinjectHttpContainer.Resolve <AuthenticationConfiguration>();

            authConfig.Config(accessTokenExpireMinutes: 120);
            authConfig.ConfigureAuth(app);

            var config = new HttpConfiguration();

            ////WebApi configuration
            WebApiConfig.Register(config);
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            // NInject config
            app.UseNinjectMiddleware(NinjectHttpContainer.GetKernel);
            app.UseNinjectWebApi(config);

            //Auto Maper
            AutoMapperStartup.Register(NinjectHttpContainer.GetKernel().GetService);

            //Logger
            ApplicationLogger.Logger.Configure();
            config.MessageHandlers.Add(NinjectHttpContainer.Resolve <DelegatingLogFilter>());

            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.UseDataContractJsonSerializer       = false;
        }