只好用偷雞的方式,將每一個 Request 的 Origin,加到 Access-Control-Allow-Origin,
算是另類的允許所有 Domain。
WebApiConfig.cs:
config.EnableCors();Global.asax.cs:
protected void Application_BeginRequest(object sender, EventArgs e)
{
//允許所有的domain
string clientOrigin = HttpContext.Current.Request.Headers["Origin"];
if (!string.IsNullOrEmpty(clientOrigin))
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin"
, clientOrigin);
}
}
沒有留言:
張貼留言