CORS enabled but response for preflight has invalid HTTP status code 404 when POSTing JSON

后端 未结 7 764
天命终不由人
天命终不由人 2020-12-01 16:04

I\'ve searched thoroughly but cannot find a solution to this issue in my particular circumstance.

Cross-domain service calls using Fiddler (POST) execute correctly a

7条回答
  •  猫巷女王i
    2020-12-01 16:35

    This worked for me.

    In Global.asax

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        //HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
        if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
            HttpContext.Current.Response.End();
        }
    }
    

    In Web.config

        
            
    
        
        
        
            
        
    

    rebuild and hey presto.

提交回复
热议问题