Closed
Description
Describe the bug
Upgraded an application from asp.net core 2.2 to 3.0 preview7
[Area("Games")]
[Route("[area]/{slug}/[controller]")]
public class FooController : Controller {
[AjaxOnly]
[HttpPost("[action]", Name = "GetFooByName")]
public async Task<JsonResult> GetFooByName(string name)
{
}
}
On my razor page I used to create the following:
<script>
var endpoints = {
getFoo: '@Url.RouteUrl("GetFooByName")' <---- no route data passed
}
</script>
Issue
But since upgrading to asp.net core 3.0 the getFoo
in 2.2 - /area/slug/controller/foo
n 3.0 - blank
<----- ????
Using Endpoints - DOESN'T WORK
services.AddRazorPages();
services.AddControllersWithViews(options =>
{
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
options.Filters.Add(new RequireHttpsAttribute());
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
options.EnableEndpointRouting = true; (doesn't matter true or false)
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); // attribute routing
endpoints.MapAreaControllerRoute("areaRoute", "{area:exists}", "{area:exists}/{slug?}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
Using AddMvc - WORKS
services.AddMvc(options =>
{
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
options.Filters.Add(new RequireHttpsAttribute());
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
// add custom binder to beginning of collection
options.EnableEndpointRouting = false;
})
app.UseMvc(routes =>
{
// Areas route
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{slug?}/{controller=Home}/{action=Index}/{id?}");
// Default route
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
I even noticed that my links no longer work correctly since the update
<a class="btn btn-sm btn-outline-info" asp-route="BarRoute" asp-route-option="foo">
The route-option value isn't on the generated url
It seems that I can't use the new use.Endpoint
Expected behavior
in 2.2 - /area/slug/controller/foo
in 3.0 - /area/slug/controller/foo