How to add Access-Control-Allow-Origin?

后端 未结 1 2033

I am getting the following error when I call my webservice method.

Origin http://localhost:4165 is not allowed by Access-Control-Allow-Origin.
1条回答
  •  甜味超标
    2020-12-30 18:05

    I have found the answer for my question. Just add the following to your web.config file

    
        
            
                
                
            
        
    
    

    Also if you dont want it to be set up globally, then you can add it to your action method alone as below:

    [WebMethod]
    public string HelloWorld()
    {
        HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
        return "Hello User";
    }
    

    0 讨论(0)
提交回复
热议问题