【发布时间】:2019-06-24 10:15:46
【问题描述】:
我在 .NET Core 2.2 上有一个 MVC Web API
当我在本地运行我的 API 时,我的路由似乎都可以正常工作,但是当我将它部署到 Azure/我的服务器上时,路由似乎返回 404 错误。
这是我的“PricesController”,其中包含编码的路线:
namespace tf.PriceService.API.Controllers
{
[Route("HorseRacingApi/prices/")]
[Produces("application/json")]
[ApiController]
public class PricesController : Controller
{
private readonly IPriceService _priceService;
public PricesController(IPriceService priceService)
{
_priceService = priceService;
}
[HttpGet]
[Route("GetPricesForRace/{meetingDate}/{courseId}/{raceNumber}/{ShowAll?}")]
public IActionResult GetPricesForRace(DateTime meetingDate, int courseId, int raceNumber, bool? ShowAll = false)
{
return Ok(_priceService.GetPricesForRace(meetingDate, courseId, raceNumber));
}
[HttpGet]
[Route("GetPriceForEntry/{meetingDate}/{courseId}/{raceNumber}/{horseCode}")]
public IActionResult GetPriceForEntry(DateTime meetingDate, int courseId, int raceNumber, string horseCode)
{
return Ok(_priceService.GetPriceForEntry(meetingDate, courseId, raceNumber, horseCode));
}
[HttpGet]
[Route("GetPriceForEntries/{ShowAll?}")]
public IActionResult GetPriceForEntries(bool? ShowAll)
{
string jsonString = null;
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
jsonString = reader.ReadToEnd();
}
List<Core.Models.JsonEntryKey> list = JsonConvert.DeserializeObject<List<Core.Models.JsonEntryKey>>(jsonString);
return Ok(_priceService.GetPriceForEntries(list));
}
}
使用以下 URL 可在本地工作: https://localhost:44374/HorseRacingApi/prices/GetPricesForRace/2019-06-24/47/1
但不适用于 Azure 版本并返回 404。我错过了什么吗?此外,如果有帮助,返回类型是 JSON。
【问题讨论】:
标签: azure .net-core model-view-controller routes