如何为 Mac 添加新的 API 控制器 VisualStudio
How To Add new API Controller VisualStudio For Mac
我开始使用 ASP.Net Core 3.1 Api 项目 Visual Studio For Mac。
我已经创建了生成的默认模板 "Weather Forecast" 控制器吐出默认天气预报数据。
现在我想添加一个控制器来完成我需要它做的事情。 "tripcalc"
所以我为 "tripcalc" 添加了一个控制器脚手架然后去更改 launchsettings.json 以指向我的新 "tripcalc" 控制器。 它仍然显示 WeatherController 数据我想知道为什么?我想我也需要以某种方式更改 Startup.cs。仅供参考,我做了一个文件搜索所有文件结尾中出现的所有事件 "WeatherForecast" 它无处存在
{
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:22536",
"sslPort": 44363
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "tripcalc",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TripCalculator.API": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "tripcalc",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5003;http://localhost:5002"
}
}
}
Startup.cs
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace TripCalculator.API
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
它只是在启动参数中
我开始使用 ASP.Net Core 3.1 Api 项目 Visual Studio For Mac。 我已经创建了生成的默认模板 "Weather Forecast" 控制器吐出默认天气预报数据。
现在我想添加一个控制器来完成我需要它做的事情。 "tripcalc"
所以我为 "tripcalc" 添加了一个控制器脚手架然后去更改 launchsettings.json 以指向我的新 "tripcalc" 控制器。 它仍然显示 WeatherController 数据我想知道为什么?我想我也需要以某种方式更改 Startup.cs。仅供参考,我做了一个文件搜索所有文件结尾中出现的所有事件 "WeatherForecast" 它无处存在
{
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:22536",
"sslPort": 44363
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "tripcalc",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TripCalculator.API": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "tripcalc",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5003;http://localhost:5002"
}
}
}
Startup.cs
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace TripCalculator.API
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
它只是在启动参数中