c# - how to map multiple routes in mvc -


i having home controller default action landing.

but errorcontroller default action should index

in registerroutes method in global.cs, had written : -

        routes.maproute(             "default", // route name             "{controller}/{action}/{id}", // url parameters             new { controller = "home", action = "landing", id = urlparameter.optional } 

but when trying redirect error application_error event : -

exception error = server.getlasterror();                     string redirecturl = "~/error/id=" + errorid; httpcontext.current.server.clearerror(); httpcontext.current.response.redirect(redirecturl); 

it throwing error - action landing not found.

just add route above current route more specific error case:

routes.maproute(             "error", // route name             "error/{action}/{id}", // url parameters             new { action = "index", id = urlparameter.optional } 

also, looks bit strange:

string redirecturl = "~/error/id=" + errorid; 

seems more this:

string redirecturl = "~/error?id=" + errorid; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -