I am facing one issue of CORS policy. Please note that I am not using web API or .NET core application where we have library to enable cors. I am using MVC application of .Net framework 4.8 Here is my step to call other resource from my MVC application. 1 - calling search action controller d.cs using ajax call from jquery 2 - checking request authentication in search action of d.cs 3 - if request is not valid then redirect to SignI action of home controller. 4 - my SignIn action redirect to Microsoft site https://login.microsoftonline.com to authenticate the request. I implemented microsoft OWIN.
Please note - this is working fine when my request is not originate from ajax/jquery.
I gone through various solutions provided, but no success Setting Access-Control-Allow-Origin in ASP.Net MVC - simplest possible method
I did following changes 1 - In web.config
<httpProtocol>
<customHeaders>
<clear />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
2 - created custom action filter and apply over my controller
public class CustomActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-
Origin", "*");
filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-
Headers", "Origin, X-Requested-With, Content-Type, Accept");
filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-
Credentials", "true");
if (filterContext.HttpContext.Request.HttpMethod == "OPTIONS")
{
filterContext.HttpContext.Response.Flush();
}
base.OnActionExecuting(filterContext);
}
}