Search code examples
.net-coreasp.net-core-mvc

.NET Core UsePathBase() why original route still working?


For example the original route is localhost:5000/Product

When I use app.UsePathBase("/admin") will cause the route localhost:5000/admin/Product working. But the original route localhost:5000/Product still working.

I expected it not enabled and I may use it for Front-end routing. How to disable it.


Solution

  • Refer to existing answer.

    • @ISR answer is not suitable for me because I want to use the original route for the front-end later.
    • This answer described UsePathBase may be used for other purposes.
    • this answer try to use Area that will affect the folder structure.

    So I decided to use the simple solution [Route("admin/[controller]")] It does not seem clever, but it solves my problem.