【发布时间】:2020-12-29 11:24:29
【问题描述】:
所以,我是 asp.net core 的新手,我正在尝试在 asp.net core 中创建一个新的 web api。默认控制器是 Weatherforecast,换句话说,当我在浏览器中调试应用程序时,主页始终是 Weatherforecast。我添加了一个名为 MainController.cs 的新控制器,并在那里编写了一些简单的代码:
[Route("[controller]")]
[ApiController]
public class MainController : ControllerBase
{
[HttpGet]
public string getmain()
{
return "welcome";
}
}
} 总之,我希望我的应用程序的主控制器是 https://localhost:43372/main 而不是 https://localhost:43372/weatherforecast,我也尝试删除 Weatherforecast 控制器和 Weatherforecast.cs 文件,但是当我删除它,主页仍然是 https://localhost:43372/weatherforecast,但是因为我删除了文件而出错。那么,我怎样才能让我的新控制器默认为我的网络应用程序?
【问题讨论】: