Reputation: 3
I have one ASP.NET Core 3.1.0 web app and I am struggling to understand the url exposed by asp.net core.
I have one single controller
[Route("accounts")]
public class AccountsController : BaseController
{
public AccountsController()
{
}
[HttpGet("{test}")]
public string DefaultMethod()
{
return "Hello";
}
}
In my Startup.cs, I am using UsePathBase as
app.UsePathBase("/account-api");
When I start the app, I can access the method as
http://localhost:5000/account-api/accounts/test and it is fine
But I can also access it via http://localhost:5000/accounts/test which I want to restrict.
How can I restrict this?
Upvotes: 0
Views: 4028
Reputation: 5215
try this
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "account-api/{controller}/{action}/{id?}");
});
Upvotes: 1