I have an ASPNET Razor pages app where i use localization; i would also need to use the same application to expose some API endpoints using minimal APIs. With this class:
public class CultureTemplatePageRouteModelConvention : IPageRouteModelConvention
{
public void Apply(PageRouteModel model)
{
var selectorCount = model.Selectors.Count;
for (var i = 0; i < selectorCount; i++)
{
var selector = model.Selectors[i];
model.Selectors.Add(new SelectorModel
{
AttributeRouteModel = new AttributeRouteModel
{
Order = -1,
Template = AttributeRouteModel.CombineTemplates("{culture?}", selector.AttributeRouteModel.Template),
}
});
}
}
}
urls for links are generated with the language, as: en/Products , en/Customers and it works fine.
The problem is that when I create a
app.MapPost("/api/Customers", () =>
{
return "TEST FROM API";
});
user is redirected to Login page instead of returning JSON because "Customers" is part of selectors used for normal urls , while:
app.MapPost("/api/APICustomers", () =>
{
return "TEST FROM API";
});
works fine because APICustomers is not part of knows urls.
I would like to avoid to use bad names like XYZCustomers, but would like to POST /api/Customers ... is there a way?