I have built an ASP.NET Core MVC application and I have used the default MVC URL routing:
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
I want to create the GET method for creating and editing the user.
For creating new user I need to go to url /Admin/User and for editing the existing user url /Admin/User/{id:int}
I have tried to create the method like this:
[HttpGet]
public async Task<IActionResult> User(int? id)
{
}
How can I restrict type of the id parameter?
I need only allow access to /Admin/User or /Admin/User/{id:int} - but if I try i.e. - /Admin/User/ABCD - (use an string as ID) - it is allowed as well.
If the parameter ID will be another type instead of number then I want to return 404.