简体   繁体   English

一个路由图中可以有多个动作吗?

[英]Can I have more than one action in a single routemap?

I have the following route set up: 我设置了以下路线:

    context.MapRoute(
        "MyAccount_default",
        "MyAccount/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );

and the following links: 以及以下链接:

/MyAccount/Access/Login
/MyAccount/Access/Logout
/MyAccount/Access/Register

Is there some way that I can create a routemap so that entering: 有什么办法可以创建路线图,以便输入:

/Login
/Logout
/Register 

Would direct the request to the MyAccount area, Access controller and Login/Logout or Register methods? 会将请求定向到MyAccount区域,访问控制器和Login / Logout或Register方法吗? If I have the routemap then can it belong inside the routemap of the MyAccount area or does it need to be outside that? 如果我有该路线图,那么它可以属于MyAccount区域的路线图,还是需要在该路线图之外?

You really should be specific with your routes. 您确实应该具体说明自己的路线。 If you want something outside of the standard routes, add those to your route tables. 如果您需要标准路线之外的东西,请将其添加到路线表中。


context.MapRoute(
        "Login",
        "/Login",
        new { controller="Access", action = "Login"}
    );

Add that before your default route. 将其添加到默认路由之前。 The other option is to use our default route, but in addition use something like the AttributeRouting project at https://github.com/mccalltd/AttributeRouting and specify your additional route on your action methods in each controller. 另一个选择是使用我们的默认路由,但除此之外,请使用https://github.com/mccalltd/AttributeRouting上的AttributeRouting项目之类的东西,并在每个控制器的操作方法上指定其他路由。

note that you could code on your Login action method something like: 请注意,您可以在登录操作方法上编写如下代码:


[GET("Login")]
public ActionResult Login()
{
}

so your default routes would be used and in addition this extended route. 因此将使用您的默认路由以及此扩展路由。 I believe that should work anyways :) 我相信无论如何应该起作用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM