[英]Can I have more than one action in a single routemap?
我设置了以下路线:
context.MapRoute(
"MyAccount_default",
"MyAccount/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
以及以下链接:
/MyAccount/Access/Login
/MyAccount/Access/Logout
/MyAccount/Access/Register
有什么办法可以创建路线图,以便输入:
/Login
/Logout
/Register
会将请求定向到MyAccount区域,访问控制器和Login / Logout或Register方法吗? 如果我有该路线图,那么它可以属于MyAccount区域的路线图,还是需要在该路线图之外?
您确实应该具体说明自己的路线。 如果您需要标准路线之外的东西,请将其添加到路线表中。
context.MapRoute(
"Login",
"/Login",
new { controller="Access", action = "Login"}
);
将其添加到默认路由之前。 另一个选择是使用我们的默认路由,但除此之外,请使用https://github.com/mccalltd/AttributeRouting上的AttributeRouting项目之类的东西,并在每个控制器的操作方法上指定其他路由。
请注意,您可以在登录操作方法上编写如下代码:
[GET("Login")]
public ActionResult Login()
{
}
因此将使用您的默认路由以及此扩展路由。 我相信无论如何应该起作用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.