目前,我的WebAPI控制器执行此操作:
var newUrl = _adminService.Foo(bar);
return Request.CreateResponse(HttpStatusCode.OK, newUrl);
因此客户端收到一个字符串,然后使用javascript设置window.location
。
这似乎是一种通过WebAPI重定向的hacky方式。我找到了这篇文章:
Redirect from asp.net web api post action
我已实施:
var newUrl = _adminService.Foo(bar);
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(newUrl);
return response;
但是现在我在chrome中遇到以下错误(从localhost导航到子域时):
XMLHttpRequest cannot load http://test.localhost:3806/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3806' is therefore not allowed access.
我需要为此配置CORS吗?