我错过了什么,我受到了404这个控制器的欢迎?我真的不想使用基于属性的路由.我也不想action成为任何URI的一部分.
我正在使用Visual Studio 2017和.Net Core 1.1.
using System;
using Microsoft.AspNetCore.Mvc;
namespace Foo.Controllers
{
public class TestController : Controller
{
public long Get() => DateTimeOffset.Now.ToUnixTimeSeconds();
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,这适用于[Route("api/Test")]属性.但我不想使用基于属性的路由.一旦我取消该属性,我就会得到404.
namespace Foo
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use …Run Code Online (Sandbox Code Playgroud)