asp.net mvc 跨域 get正常 post有问题 OPTIONS 返回404 完美解决方法 【小白篇】
global.asax.cs文件中 增加
private void Application_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
//HttpContext.Current.Response.StatusCode = 200;
HttpContext.Current.Response.End();
}
}如下图
![](https://img2018.cnblogs.com/blog/818001/201912/818001-20191203231504503-2055480072.png)
web.config文件增加
<!--配置跨域访问-->
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type,x-token" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>如下图
![](https://img2018.cnblogs.com/blog/818001/201912/818001-20191203231504950-719472719.png)