c# - ASP.NET Core 2.x 默认为不存在路由
问题描述
如何更改 ASP.NET Core 中的默认路由
路线很奇怪其实是
api/值
它不再存在,我已经删除了控制器,就是这样,我刚刚创建了一个 Home 控制器,其余的都是 API。为什么还有这条路线存在?
这是我想默认的控制器
public class HomeController : Controller
{
public IActionResult Index()
{
return new RedirectResult("~/swagger");
}
}
我试过这个答案
.net Core - 使用 Route 属性时未加载默认控制器
但对我不起作用
这是我的配置
public void ConfigureServices(IServiceCollection services)
{
.AddMvc(options =>
{
})
.AddControllersAsServices()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvcWithDefaultRoute();
}
解决方案
属性下有一个launchSettings.json 。您可以使用默认路由更改launchUrl字段。
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63986",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values", //change here
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication1": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values", //change here
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
推荐阅读
- redirect - WSFederation ADFS 登录循环.Net Core 2.1
- d3.js - 使用 d3 创建 InnerWidth 和 InnerHeight 使网格不在边框上
- android - 如何使用 Flutter 插件修复 androidX 问题?
- python - python中的“fillna”命令不返回使用熊猫的意思
- javascript - 如何在 react-navigation 中向 stackNavigator 中的所有屏幕添加公共背景图像?
- ansi-escape - 是否有将光标移动到行尾的 ANSI 控制序列?
- ios - 您如何访问和保存集合视图中单个单元格的数据?
- php - Docker 上的 Wordpress 未加载正确的页面:Nginx 在 404 后发送 301 和 /$uri/index.php 未找到错误(没有这样的文件或目录)
- c - C:要求用户输入一个字符串。编写一个以字符串为参数的函数,如上所述加密消息并返回密文
- python - 根据条件为列名和单元格添加背景颜色