Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

45 rindas
1.7 KiB

  1. using Nancy;
  2. using Nancy.Bootstrapper;
  3. using Nancy.TinyIoc;
  4. namespace Learun.Application.WebApi
  5. {
  6. /// <summary>
  7. /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园
  8. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  9. /// 创建人:数字化智慧校园-框架开发组
  10. /// 日 期:2017.05.12
  11. /// 描 述:Nancy启动重载(用于解决跨域问题)
  12. /// </summary>
  13. public class Bootstraper : DefaultNancyBootstrapper
  14. {
  15. /// <summary>
  16. /// 自定义请求启动函数
  17. /// </summary>
  18. /// <param name="container"></param>
  19. /// <param name="pipelines"></param>
  20. /// <param name="context"></param>
  21. protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
  22. {
  23. //CORS Enable
  24. pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
  25. {
  26. var originlist = ctx.Request.Headers["Origin"];
  27. foreach (var origin in originlist)
  28. {
  29. ctx.Response.WithHeader("Access-Control-Allow-Origin", origin);
  30. }
  31. ctx.Response.WithHeader("Access-Control-Allow-Methods", "POST,GET")
  32. .WithHeader("Access-Control-Allow-Credentials", "true")
  33. .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type");
  34. });
  35. }
  36. protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
  37. {
  38. base.ApplicationStartup(container, pipelines);
  39. Nancy.Json.JsonSettings.MaxJsonLength = int.MaxValue;
  40. }
  41. }
  42. }