I'm creating multi-tenancy application, with single database per library, for example.
I want to dynamically add library name to route, for example, when user trying to get all books
/Books/GetAllBooks, I must add library name, which could be retrieved from database, for example:
/LibraryName/Books/GetAllBooks, so the user can get all books only from the library, which he belongs to.
What should I do? Implement my own IRouter, my own template route, something else?
id to your url. Look at url of this question:
You can change last path segment to anything:
https://stackoverflow.com/questions/36718499/foo-bar still bring you here.
IRouter. You will need to implement two methods:
async Task RouteAsync(RouteContext context) which parse incoming request and add correct "controller", "action" and "id" values into
context.RouteData collection. Later, MVC will use this info to call your controller.
VirtualPathData GetVirtualPath(VirtualPathContext context) which builds url (string) for controller+action+id values, provided in
This can help you: