手动给配置,添加如下方法
protected void Application_BeginRequest(object sender, EventArgs e)
{
app = sender as ;
HttpResponse response = ;
//支持跨域
if ( == "OPTIONS")
{
//支持跨域
("Access-Control-Allow-Methods", "*");
("Access-Control-Allow-Headers", "*");
("Access-Control-Allow-Origin", "*");
("Cache-Control", "no-cache");
= 200;
();
}
else
{
("Access-Control-Allow-Origin", "*");
("Access-Control-Allow-Headers", "*");
("Access-Control-Allow-Methods", "*");
("Cache-Control", "no-cache");
//("Access-Control-Allow-Methods", "GET, POST,PUT, DELETE");
//("Access-Control-Allow-Headers", "Content-Type");
}
}
最后记得退出所有终端,重新进入终端即可解决跨域报错问题。