خرید بک لینک

Vote count: 0

I have some Web API server methods that include the following POST action. Without specifying the [Route()] directive, the response completes fine with CreatedAtRoute(). When setting the directive (with and without the tilde), then that method fails. Changing it to Created() makes it succeed.

[HttpPost]
[Route("~/api/ExamTaken")]
[Authorize]
[ResponseType(typeof(ExamTaken))]
public async Task<IHttpActionResult> PostExamTaken(ExamTaken ExamTaken)
{
    // ...

    db.ExamsTaken.Add(ExamTaken);
    await db.SaveChangesAsync();

    // This line fails
    //return CreatedAtRoute("DefaultApi", new { id = ExamTaken.Id }, ExamTaken);
    // This line succeeds
    return Created(ExamTaken.Id.ToString(), ExamTaken);

    // ...
}

In all cases, the method is found and entered, and appears to complete successfully; debugging reaches the end of the code, even passing a temporary catch block. However, the request generates a 500 Internal Server Error and contains no Location header when specifying the Route and using CreatedAtRoute().

This isn't really an issue, as I can use Created() for what I need. However, I'm at a loss as to why it fails with CreatedAtRoute() when the Route directive is the same as the route comment added by the autogenerator. What's going on here? I figure it's having trouble mapping to a route, but I don't know what I can do to help that.

asked 39 secs ago

برچسب: web api createdatroute,web api createdatroute example,web api post createdatroute, نویسنده: استخدام کار تاريخ: جمعه 16 مهر 1395 ساعت: 8:23

صفحه بندی