using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace BotApiV2
{
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.AddMvcCore()
.AddApiExplorer();
services.AddRazorPages();
services.AddSwaggerGen();
}
// 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();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
}
}
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using BotApiV2.DataLayer;
namespace BotApiV2
{
[ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ValuesController))]
[Route("api/values")]
public class ValuesController : ControllerBase
{
[HttpGet]
[Route("test")]
public ActionResult Test()
{
var x = new BotDatabaseContext();
var t = new Dictionary
{
{ "test1", "value1" },
{ "test2", "value2" },
{ "test3", "value3" }
};
return new JsonResult(t);
}
}
}
Однако переход к /api/values/test не найден. Что-то настроено неправильно? Я ориентируюсь на .NET 5.0 (я также пробовал .NET Core 3.1, тот же результат).
У меня Startup.cs настроен так: [code]using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting;
namespace BotApiV2 { 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.AddMvcCore() .AddApiExplorer();
// 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(); } else { app.UseExceptionHandler("/Error"); }
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });
[/code] и мой контроллер настроен следующим образом: [code]using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using BotApiV2.DataLayer;
namespace BotApiV2 { [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ValuesController))] [Route("api/values")] public class ValuesController : ControllerBase { [HttpGet] [Route("test")] public ActionResult Test() { var x = new BotDatabaseContext();
var t = new Dictionary { { "test1", "value1" }, { "test2", "value2" }, { "test3", "value3" } }; return new JsonResult(t); } } } [/code] Однако переход к /api/values/test не найден. Что-то настроено неправильно? Я ориентируюсь на .NET 5.0 (я также пробовал .NET Core 3.1, тот же результат).