Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederikprijck/72f1f02d3e379f976f5e23de7dcd3d2a to your computer and use it in GitHub Desktop.
Save frederikprijck/72f1f02d3e379f976f5e23de7dcd3d2a to your computer and use it in GitHub Desktop.
// 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