I have the following implementation of my router:
public class TenantUrlResolverRouter : IRouter
{
private readonly IRouter _defaultRouter;
public TenantUrlResolverRouter(IRouter defaultRouter)
{
_defaultRouter = defaultRouter;
}
public VirtualPathData GetVirtualPath(VirtualPathContext context)
{
return _defaultRouter.GetVirtualPath(context);
}
public async Task RouteAsync(RouteContext context)
{
var oldRouteData = context.RouteData;
var newRouteData = new RouteData(oldRouteData);
newRouteData.Values["library"] = "Default";
try
{
context.RouteData = newRouteData;
await _defaultRouter.RouteAsync(context);
}
finally
{
if (!context.IsHandled)
{
context.RouteData = oldRouteData;
}
}
}
}
Then I define it in Startup.cs
:
app.UseMvc(routes =>
{
routes.Routes.Add(
new TenantUrlResolverRouter(routes.DefaultHandler));
routes.MapRoute(
name: "default",
template: "{library=Unknown}/{controller=Home}/{action=Index}/{id?}");
});
But nothing happens, RouteData.Values
in RouteContext
always empty, I always have Unknown, while it's need to be Default. That's not the problem of the predefined template, because it even worked without the {library=Unknown}
and this {library}/{controller=Home}/{action=Index}/{id?}
doesn't work too.
What's the problem with this custom IRouter?