/// <summary> /// Cors扩展 /// </summary> public static class IPipelinesExtensions { /// <summary> /// CORS Enable /// </summary> /// <param name="pipelines">pipelines</param> public static void UserCors(this IPipelines pipelines) { pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) => { ctx.Response.WithHeader("Access-Control-Allow-Origin", "*") .WithHeader("Access-Control-Allow-Methods", "POST,GET") .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type"); }); } } /// <summary> /// Nancyfx Ioc /// </summary> public class MyBootstrapper : DefaultNancyBootstrapper { protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { // pipelines.UserCors(); base.ApplicationStartup(container, pipelines); } protected override void ConfigureApplicationContainer(TinyIoCContainer container) { container.Register<ISys_User, Sys_User> base.ConfigureApplicationContainer(container); } }