4

Do I need to configure anything to use attribute routing in an ASP.NET Core 1.0 application?

The following doesn't seem to be working for me. I was expecting to hit this method when I go to localhost:132/accounts/welcome

public class AccountsController : Controller
{

   [Route("welcome")]
   public IActionResult DoSomething()
   {
       return View();
   }

}
0

2 Answers 2

7

An alternative you can use is to apply a RoutePrefix or Route on your class. Then you won't have to repeat that part on the action attributes.

[Route("[controller]")]
public class AccountsController : Controller
{
   [Route("welcome")]
   public IActionResult DoSomething()
   {
       return View();
   }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Looks like I needed to add the controller token in there

public class AccountsController : Controller
{

   [Route("[controller]/welcome")]
   public IActionResult DoSomething()
   {
       return View();
   }

}

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.