我正在从远程网页发布到 Azure 上的 Web API。我使用以下内容:
$.ajax({
type: "POST",
url: BaseHref + "/api/PIRknownPersons/",
data: data,
contentType: "application/json; charset=UTF-8",
success: function (response) {
//alert('Saved known ');
},
error: function (e) {
//alert('Unable to save Known ' );
}
});
我可能是错的,但看起来远程发布在 Azure 上被阻止,因为当我在本地执行代码时,代码运行良好。是这样吗?Azure 上是否有可以关闭的设置?
PIRknownPersons -
namespace TripWeb.Controllers
{
public class PIRknownPersonsController : ApiController
{
private TripDB3Entities db = new TripDB3Entities();
// POST: api/PIRknownPersons
[ResponseType(typeof(bool))]
public HttpResponseMessage Post([FromBody]ApiPIRknownPerson APIPIRknownPerson)
{
var inst = db.Institutions.Where(x => x.RemoteID == APIPIRknownPerson.RemoteID).FirstOrDefault();
if (inst == null)
{
return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Action Not Authorized");
}
var newPIRknownPerson = ObjectMapper.GetEfApiPIRknownPerson(APIPIRknownPerson);
try
{
db.PIRknownPersons.Add(newPIRknownPerson);
db.SaveChanges();
return Request.CreateResponse<bool>(HttpStatusCode.OK, true);
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
}
}