找到了多个与URL匹配的控制器类型. ASP.Net MVC [英] Multiple controller types were found that match the URL. ASP.Net MVC
问题描述
这是关于使用route属性定义路由的信息.我有两个控制器
This is regarding defining routes using route attribute. I have two controllers
第一个控制器
[AllowAnonymous]
[Route("Member/Login")]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
第二个控制器
[Route("{CategoryURL}/{Keywords}")]
public ActionResult BrowseProducts(string CategoryURL, string Keywords)
{
}
我遇到以下错误,如果尝试访问URL xyz.net/Member/Login
I am getting below error If try to access URL xyz.net/Member/Login
找到了多个与URL匹配的控制器类型.如果多个控制器上的属性路由与请求的URL匹配,则会发生这种情况. 该请求已找到以下匹配的控制器类型: XYZ.Controllers.AccountController XYZ.Controllers.CoursesController
Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL. The request has found the following matching controller types: XYZ.Controllers.AccountController XYZ.Controllers.CoursesController
我知道我有第二个控制器的可选参数,因此,当我尝试访问xyz.net/Member/Login时,它会找到两个要执行的操作方法并得到多控制器"错误.
I am aware that I have Optional Parameters for second controller, hence when I try to access xyz.net/Member/Login, it finds two action methods to go for and getting the Multiple controller error.
我的问题是,如何在不更改当前路由的情况下解决此问题.我尝试了顺序",优先级",但没有解决.
My question is, how could I fix this issue without changing my current Routings. I tried Order, Precedence but nothing worked out.
推荐答案
Web api约束也可能适用于您要完成的工作
The web api constraints may also aply for what you are trying to accomplish
http://www.asp.net/web-api/overview/web-api-routing-and-actions
这篇关于找到了多个与URL匹配的控制器类型. ASP.Net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!