0

With conventional routing, you can customize the URL that is generated by an Anchor Tag Helper by implementing IRouter.GetVirtualPath. GetVirtualPath isn't called when using attribute routing, however. Is there an equivalent way to customize the URL for an anchor that links to an action with attribute routing?

The setup code for conventional routing looks like this:

app.UseMvc(config => {
    config.Routes.Add(new MyRouter());
    // ... more routes ...
});

class MyRouter : IRouter
{
    public VirtualPathData GetVirtualPath(VirtualPathContext context)
    {
        // ... customize URL here ...
    }
}

An example of customizing the URL is to add a query parameter containing a simulated sub-domain.

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • With attribute routing you simply provide the route template to generate the URL. `[Route("customized route here")]` Can you provide a [mcve] of a case where you try to use attribute routing to generate a customized URL. – Nkosi Jan 24 '18 at 12:31
  • Not really sure what your question is here. – DavidG Jan 24 '18 at 12:36
  • I updated the question to add a link to an example of when you'd want to customize the URL. – Edward Brey Jan 24 '18 at 12:47

0 Answers0