【发布时间】:2022-05-06 05:22:14
【问题描述】:
我们将 .NET Core Web API 部署为 Azure Web 应用程序。所有端点都在本地工作,但是,一旦部署,我们就有一个控制器,它为我们在其中命中的所有端点提供 404。
我们已经检查并三次检查了我们调用的 url 是否正确,据我们所知,这个控制器与我们应用程序中的其他控制器没有什么不同。
这是给我们 404 的 BinController:
namespace API.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class BinController : ControllerBase
{
private readonly IBinRepository _binRepo;
private readonly ILogger _logger;
public BinController(IBinRepository binRepo, ILogger<BinController> logger)
{
_binRepo = binRepo;
_logger = logger;
}
[HttpGet("{locationId}/{binId}")]
public async Task<IActionResult> CheckBinExists(int locationId, string binId)
{
try
{
bool result = await _binRepo.CheckBinExists(locationId, binId);
return Ok(result);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
}
[HttpGet("findAll/{locationId}/{itemId}")]
public async Task<IActionResult> FindAllBinsWithItem(int locationId, string itemId)
{
try
{
var result = await _binRepo.FindAllBinsWithItem(locationId, itemId);
return Ok(result);
}
catch (Exception e)
{
_logger.LogError(e.Message);
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
}
[HttpGet("contents/{locationId}/{bin}")]
public async Task<IActionResult> GetBinContents(int locationId, string bin)
{
try
{
List<BatchLine> contents = await _binRepo.GetBinContents(locationId, bin);
return Ok(contents);
}
catch (Exception e)
{
_logger.LogError(e.Message);
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
}
}
}
我们打电话给https://ourapiname.azurewebsites.net/api/Bin/1234/TestBin。
总结:
- 所有端点都在本地工作
- 所有控制器在部署时都能正常工作,除了一个
- 我们的应用程序中有多个其他控制器具有类似的设置(如果不一样的话),但是这个在部署时返回 404
我们看到了这些类似的帖子,但他们没有解决这个问题:
- Web API interface works locally but gets 404 after deployed to Azure Website
- Web api call works locally but not on Azure
我希望我能提供更多的见解,但我们真的对这里可能发生的事情感到茫然。任何想法将不胜感激。
【问题讨论】:
-
这个有日志吗?就像在应用程序洞察或内部日志记录中一样。
标签: azure asp.net-core azure-web-app-service