1

I am migrating Asp.net(.net framework) project Asp.net core(.net core 3.1 framework). I am unable to find the alternate to

 [RoutePrefix("api/{controller})] 

in .net core 3.1?

Any idea, how we can achieve this?

4
  • 1
    you can use [Route("api/{controller})] as well Commented Mar 1, 2021 at 21:17
  • Just use the Route attribute. Commented Mar 1, 2021 at 21:19
  • How it work if we have [Route("GetData")] at method level? Commented Mar 1, 2021 at 21:20
  • You then would need the [HttpGet] attribute on that method... and your route would be something like: [Route("~/api/People/GetData")]. Commented Mar 1, 2021 at 21:21

2 Answers 2

3

I am using for example:

[Route("api/[controller]")]
[Route("api/[controller]/[action]")]
Sign up to request clarification or add additional context in comments.

Comments

1

If you put [Route("api/[controller]")] at the controller level, you can use [Route("Action")] on the method, and the route will be site.com/api/controller/Action.

Something to note is that if you use Route("/Action")] (with a slash), it will overwrite the controller-level route and just give you the action (site.com/Action)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.