Asp.net core 2 Prefix Routing

How to create prefix routing for MVC CRUD operation. I am working on an application that requires an administrator and interface. For the administrator, I want the entire route to point tolocalhost:5000/admin/....

I have different controllers

public class RoomsController : Controller
{
    // GET: Rooms        
    public async Task<IActionResult> Index()
    {

        return View(await _context.Rooms.ToListAsync());
    }

    //...
}

and

public class SlidersController : Controller
{
    private readonly ApplicationDbContext _context;

    public SlidersController(ApplicationDbContext context)
    {
        _context = context;
    }

    // GET: Sliders
    public async Task<IActionResult> Index()
    {
        return View(await _context.Sliders.ToListAsync());
    }

    //...
}

Now I want the admin route to be

localhost:5000/admin/rooms
localhost:5000/admin/slider

while the rest of the routes remain

localhost:5000/
localhost:5000/about
localhost:5000/...
+4
source share
1 answer

I solve the problem using the MVC docs scope

+2
source

Source: https://habr.com/ru/post/1691176/


All Articles