首页 > 解决方案 > 通过 Visual Studio 2019 运行 ASP.NET Core 应用程序

问题描述

我在 Visual Studio 2019 中创建了一个新的 ASP.NET Core 应用程序(只是一个 API,而不是 Razor),当我按 F5 时,它会在浏览器中打开一个页面“ https://localhost:44357/space/test " 这给出了 404 错误。控制器定义如下:

    [Route("[controller]")]
    [ApiController]
    public class SpaceController : ControllerBase
    {
        [HttpGet("test")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        public async Task<ActionResult<string>> GetTestAsync()
        {
            return "Hi";
        }

所以我会假设当它到达那里时我会在页面上得到一个“嗨”。为什么我会收到失败响应?

标签: asp.net-coreasp.net-core-3.0

解决方案


如果缺少某些东西,请检查您的启动课程,我在您的示例中取得了成功。


推荐阅读