Search code examples
c#asp.netajaxasp.net-mvc-4sencha-touch-2

MVC .Net project have no 'Access-Control-Allow-Origin' header when deploy on real server


I'm working with Ajax on Sencha and MVC4 .Net. This error occured:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access.

I added this Attribute

public class AllowCrossSiteJsonAttribute : 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");  
base.OnActionExecuting(filterContext);  
}  
}.  

then I assign it to my controller. It work perfect in my localhost debug but when I deploy all code of this project to my server( IIS6, .NET 4.0). The error comeback.
So could you tell me what different that make the error occur in my real server?


Solution

  • I've seen this with CORS requests... perhaps setting useDefaultXhrHeader to false will help.