ASP.NET WEBAPI cross-domain request 405 error

Browser error 

 

Originally, this error was not reported. When I added the request header information in ajax, an error was reported

The 405 error is probably that the back-end program did not allow the request. To solve this problem, the request is allowed to pass in the back-end program. The specific operation is to modify the web.config configuration item, as shown in the following figure:

It looks like this after modification:

The added configuration information is as follows:

    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Methods" value="POST,GET" />
        <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type,authorization,mypara,username,token" />
      </customHeaders>
    </httpProtocol>

 Among them, the value value of the Access-Control-Allow-Headers configuration item needs to be configured according to the actual situation. If you need to add a parameter to the request header, you must add the parameter name here.

 

 

Guess you like

Origin blog.csdn.net/liangmengbk/article/details/109212148