【发布时间】:2014-07-31 10:16:49
【问题描述】:
我们的项目由客户端(knokout)和服务器端(ASP.Net MVC 和 WebAPI)两部分组成。
客户端经常调用 Web API 来获取/创建/更新服务器上的数据。 我们按以下方式处理(更新示例)
public HttpResponseMessage UpdateEntity(EntityWE entity)
{
HttpResponseMessage response;
try
{
var updateEntity = this.someBl.UpdateEntity(entity);
response = Request.CreateResponse(HttpStatusCode.Created, updateEntity);
response.Headers.Location = new Uri(Url.Link(WebApiRoutNames.CustomApi, new { id = updatedEntity.PageId }));
}
catch (Exception ex)
{
Logger.Error(ex);
response = Request.CreateResponse(HttpStatusCode.InternalServerError);
}
return response;
}
问题是为什么我们需要发送标头位置来响应 ajax 调用?
response = Request.CreateResponse(HttpStatusCode.Created, updateEntity)不够吗?;
我们不使用任何重定向来响应 ajax 调用
附:所有写这篇文章的人都在很远的地方......我无法理解它被添加到所有 Web API 控制器的原因
提前感谢您的澄清。
【问题讨论】:
标签: asp.net ajax asp.net-web-api