简体   繁体   中英

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? If I have the routemap then can it belong inside the routemap of the MyAccount area or does it need to be outside that?

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.

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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