我创建了一个ASP.NET Core应用程序,其中包含一些工作正常的控制器。
路由系统的结构类似于 https://something.com/api/controller 。
但是,我在Azure中使用始终在线选项来保持Web应用程序始终处于活动状态,并且在空闲时不会暂停。
问题是,每隔5分钟,Azure会使用地址 https://something.com 对我的应用进行ping操作,并返回404错误,该错误会记录在我的Application Insights报告中。
我想知道如何处理对应用根目录发出的请求,并返回200 HTTP结果。
这是我的Startup类:
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();
}
private IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddSingleton<ICachingService>(e => new CachingService(Configuration["Redis:ConnectionString"]));
var loggingService = new LoggingService(Configuration["ApplicationInsights:InstrumentationKey"]);
services.AddSingleton(typeof(ILoggingService), loggingService);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
}
}
答案 0 :(得分:2)
好吧,事实上它非常简单:
npm install module_name --save
答案 1 :(得分:0)
public void Configure(IApplicationBuilder app)
{
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", (context) => context.Response.WriteAsync("Success"));
});
}