我正在尝试为我的 C# 和 .Net Core Web 应用程序设置 Rest-API。在使用标准 ASP.NET Core Web 应用程序模板并向具有读/写操作的 API 控制器的包中添加控制器时,我认为 URL:https://localhost:5001/api/values 会给我一个响应。相反,它会返回错误 (404)。
ValuesController.cs代码:
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// For more information on enabling Web API for empty projects, visit
https://go.microsoft.com/fwlink/?LinkID=397860
namespace CSharp_met_database.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET: api/<ValuesController>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<ValuesController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
} …Run Code Online (Sandbox Code Playgroud)