У меня есть следующее простое решение с одной Области с именем Test:

В моем файле Startup.cs:
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.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
services.AddControllersWithViews();
services.AddRazorPages();
}
// 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("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "test",
pattern: "Test/{controller=Map}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
}
И в MapController.cs:
[Area("Test")]
[Route("test/[controller]")]
public class MapController : Controller
{
public IActionResult Index()
{
return View();
}
[Route("[action]")]
public IActionResult LoadNearbySitesAsync()
{
return Ok("data");
}
}
Когда я пытаюсь достичь https://localhost: 44319 / Test / Map / Index , появляется страница Index. Когда я пытаюсь достичь https://localhost: 44319 / Test / Map / LoadNearbySitesAsyn c, я получаю исключение HTTP 404:

Я также получаю исключение HTTP 404 при попытке доступа к методу LoadNearbySitesAsync
с помощью функции jQuery $.get
.
Раньше я использовал ASP. NET Core 2.2 и это работало нормально. Теперь, когда я переключился на ASP. NET Core 3.1 и новые функции Endpoints, я не могу заставить это работать.
Я пробовал разные комбинации атрибутов [Area]
и [Route]
, я даже добавил атрибут [Route("[action]")]
в метод LoadNearbySitesAsync
, пока ничего не получалось.
Есть идеи, что мне здесь не хватает?