using System.Web.Helpers; using FHT.Agency.Web; using FHT.Core.Infrastructure.Authentication; using FHT.Core.Infrastructure.MsSqlConfigurations; using Microsoft.Owin; using Owin; [assembly: OwinStartup(typeof(Startup))] namespace FHT.Agency.Web { public partial class Startup { public void Configuration(IAppBuilder app) { app.CreatePerOwinContext(FhtDbContext.Create);//这个Middleware会创建一个新的FhtDbContext per Request app.CreatePerOwinContext(FhtUserManager.Create); app.Use(async (context, next) => { IOwinRequest req = context.Request; IOwinResponse res = context.Response; if (req.Path.StartsWithSegments(new PathString("/Token"))) { string origin = req.Headers.Get("Origin"); if (!string.IsNullOrEmpty(origin)) { res.Headers.Set("Access-Control-Allow-Origin", origin); res.Headers.AppendCommaSeparatedValues("Access-Control-Allow-Credentials", "true"); } if (req.Method == "OPTIONS") { res.StatusCode = 200; res.Headers.AppendCommaSeparatedValues("Access-Control-Allow-Methods", "GET", "POST"); res.Headers.AppendCommaSeparatedValues("Access-Control-Allow-Headers", "authorization", "content-type"); return; } } await next(); }); ConfigureAuth(app); ConfigureHangfire(app); AntiForgeryConfig.CookieName = "__AgencyRequestVerificationToken"; } } }