C# ASP.NET Core 2.x默认为不存在路由
如何更改ASP.NET Core中的默认路由 这条路线很奇怪,实际上是 空气污染指数/数值 已经不存在了,我删除了控制器,就是这样, 我刚刚创建了一个主控制器,其余的都是API。 为什么还有这条路线 这是我想要默认设置的控制器C# ASP.NET Core 2.x默认为不存在路由,c#,asp.net-core,.net-core,asp.net-core-mvc,asp.net-core-2.0,C#,Asp.net Core,.net Core,Asp.net Core Mvc,Asp.net Core 2.0,如何更改ASP.NET Core中的默认路由 这条路线很奇怪,实际上是 空气污染指数/数值 已经不存在了,我删除了控制器,就是这样, 我刚刚创建了一个主控制器,其余的都是API。 为什么还有这条路线 这是我想要默认设置的控制器 public class HomeController : Controller { public IActionResult Index() { return new RedirectResult("~/
public class HomeController : Controller
{
public IActionResult Index()
{
return new RedirectResult("~/swagger");
}
}
我试过这个答案
但对我不起作用
这是我的配置
public void ConfigureServices(IServiceCollection services)
{
.AddMvc(options =>
{
})
.AddControllersAsServices()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvcWithDefaultRoute();
}
有一个launchSettings.json属性下的位置。您可以使用默认路由更改启动URL字段
{
"$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"
}
}
}
}
有一个launchSettings.json属性下的位置。您可以使用默认路由更改启动URL字段
{
"$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"
}
}
}
}
为什么您甚至想要一个控制器来重定向到swagger UI?只需按照文档中的描述注册SwaggerUI即可。您可以在那里配置端点,在该端点下可以使用swagger ui…swagger只是一个示例,我可以使用那里的任何东西,想法仍然是,为什么它不工作?为什么我看到一个不应该存在的路由?为什么你甚至想要一个控制器来重定向到swagger UI?只需按照文档中的描述注册SwaggerUI即可。您可以在那里配置端点,在该端点下可以使用swagger ui…swagger只是一个示例,我可以使用那里的任何东西,想法仍然是,为什么它不工作?为什么我看到一条不应该存在的路线?