其可能的,假設你正在使用的Microsoft.AspNet.WebApi.Cors在您的API使CORS,你需要定義自己的一個Cors策略提供者:
public class MyApiCorsPolicy : Attribute, ICorsPolicyProvider
{
private System.Web.Cors.CorsPolicy _policy;
public MyApiCorsPolicy()
{
// Create a CORS policy.
_policy = new System.Web.Cors.CorsPolicy
{
AllowAnyMethod = true,
AllowAnyHeader = true,
SupportsCredentials = true
};
}
public Task<System.Web.Cors.CorsPolicy> GetCorsPolicyAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
// Add the Request origin to the response.
_policy.Origins.Add(request.GetCorsRequestContext().Origin);
return Task.FromResult<System.Web.Cors.CorsPolicy>(_policy);
}
}
接下來,在你的ASP.NET網頁API配置代碼,您需要在啓用Cors時通過此政策:
config.EnableCors(new MyApiCorsPolicy());
完美謝謝。 – 2014-09-03 17:13:04