Created
July 5, 2016 13:32
-
-
Save frederikprijck/72f1f02d3e379f976f5e23de7dcd3d2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filter | |
public class CorsFilter : ActionFilterAttribute | |
{ | |
public override void OnActionExecuted(ActionExecutedContext filterContext) | |
{ | |
base.OnActionExecuted(filterContext); | |
var response = filterContext.RequestContext.HttpContext.Response; | |
// Add header to response | |
response.AddHeader("Access-Control-Allow-Origin", "*"); | |
response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
response.AddHeader("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS"); | |
} | |
} | |
// New controller | |
public class Test3Controller : Controller | |
{ | |
[CorsFilter] | |
[HttpPost] | |
public ActionResult Xlsx(string data, string name) | |
{ | |
/* ... implementation here ... */ | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment