Sunday 15 August 2010

c# - MVC5 route prefix setup, how to? -



c# - MVC5 route prefix setup, how to? -

what want : add together prefix after action name, browser's url bar can seen like.

http://stackoverflow.com/ask ↓↓↓↓ http://stackoverflow.com/ask.mon

and want invoke specific controller prefix well.

http://stackoverflow.com/loginprocess.mon

if invoking above, below action can called.

updated : ( remember, don't want show controller's name on url bar. )

public class logincontroller : controller { public actionresult loginprocess() { homecoming view(); } } . .

what did : set route config below.

public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( name: "default", url: "{action}.mon/{id}", defaults: new { controller = "login", action = "index", id = urlparameter.optional } ); }

and controller looks like...

public class logincontroller : controller { public actionresult index() { if (session["userinfo"] != null) { homecoming redirecttoaction("main", "web"); } else { homecoming view(); } } . . .

what happened : throws me 404 error.

what should avoid this?

to requested url (http://stackoverflow.com/login/loginprocess.mon) work, mapping not include controller. next code should prepare routing.

routes.maproute( name: "default", url: "{controller}/{action}.mon/{id}", // added {controller} routing login/loginprocess.mon work defaults: new { controller = "login", action = "index", id = urlparameter.optional } );

then code action in logincontroller should work great.

public actionresult loginprocess() { homecoming view(); }

c# asp.net-mvc routes asp.net-mvc-5

No comments:

Post a Comment