asp.net 跨域访问

摘自

https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

引用System.Web.Http.Cors

在一下类型中可添加[EnableCors(XXXX)]

  1. Action
  2. Controller
  3. Global

测试:

c#

var xhr = new XMLHttpRequest();
xhr.open('get', 'http://www.example.com/api/test');
xhr.withCredentials = true;

jquery:

$.ajax({
type: 'get',
url: 'http://www.example.com/api/test',
xhrFields: {
withCredentials: true
}

转载于:https://www.cnblogs.com/mabelhua/p/9802724.html

猜你喜欢

转载自blog.csdn.net/weixin_33754065/article/details/93902554