ServiceControllerFilter.cs 1013 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace EMIS.Web.Controls.Filters
  7. {
  8. public class ServiceControllerAttribute : ActionFilterAttribute
  9. {
  10. public override void OnActionExecuting(ActionExecutingContext filterContext)
  11. {
  12. if (filterContext.Controller.GetType().Namespace.StartsWith("EMIS.Web.ApiControllers"))
  13. {
  14. try
  15. {
  16. filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
  17. filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Methods", "POST");
  18. filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Headers", "x-requested-with,content-type");
  19. }
  20. catch (Exception ex)
  21. {
  22. throw ex;
  23. }
  24. }
  25. base.OnActionExecuting(filterContext);
  26. }
  27. }
  28. }