1

I have a controller with Route attribute as well as every Action with it`s own Route like:

[Route("api/version/v1")]
public class MyController : ControllerBase
{
   [Route("receipts/verifyReceipt")]
   public IActionResult VerifyReceipt(...){....}
   
   ...... several actions with diffrent Routes

}

My aim is to have api route : 'api/version/v1/receipts/verifyReceipt'

How can I set prefix [Route("api/version/v1")] from config.json

I`ve tried to set it up from Startupt.cs

app.UseMvc(routes =>
        {
            routes.MapRoute( "default",  apiCommon.Value);
        });

where 'apiCommon.Value' is my prefix 'api/version/v1' While adding route attribute to MyController:

[Route("", Name = "default")]

But that seems to have no effect. And api route looks like this: '/receipts/verifyReceipt'

Any Ideas what I`am doing wrong?

2 Answers2

1

I think UsePathBase() fits your needs best. It does routing after the pathbase use specified

call it before app.UseRouting()

app.UsePathBase(apiCommon.Value);
0

Found the solution for my problem on Global route prefixing in ASP.NET Core MVC