首页 > 解决方案 > asp.net core 3.1 更改路由

问题描述

有没有简单的方法来改变 asp.net core 3.1 控制器的路由?

目前我有控制器PicVideosControllerURL: ...\picvideos... 并且我被要求将 URL 修改为 ...\picturesvideos...

我在控制器端添加了一条路线:

[Route("picturesvideos")]
public class PicVideosController : Controller

得到一个错误AmbiguousMatchException: The request matched multiple endpoints. Matches: Main.Controllers.PicVideosController.Pay (Main) Main.Controllers.PicVideosController.Completed (Main)似乎仍然是在查看原始 url

标签: c#asp.net-core.net-coreroutesasp.net-core-3.1

解决方案


尝试这个:

[Route("picturesvideos/[action]")]
public class PicVideosController : Controller
{
[Route("/")]
[Route("~/picturesvideos")]
[Route("~/picturesvideos/index")]
public IActionResult Index()
....

推荐阅读