ASP.NET MVC - prevent fallback to default route if mandatory parameter specified -


i have following route:

    routes.maproute(         "setpassword",         "account/setpassword/{token}",         new { controller = "account", action = "setpassword" }     ); 

and want token mandatory. problem if token missing, route falls default one:

    routes.maproute(         name: "default",         url: "{controller}/{action}/{id}",         defaults: new { controller = "home", action = "index", id = urlparameter.optional }     ); 

what want return 404 not found if enters address http://mysite.com/account/setpassword

how specify token mandatory parameter , routing must stop @ route if controller , action names match specification?

one thing put route constraint on default route, preventing matching actions in account controller:

routes.maproute(     name: "default",     url: "{controller}/{action}/{id}",     defaults: new { controller = "home",                          action = "index",                              id = urlparameter.optional },     constraints: new routevaluedictionary { { "controller", "^(?!account$).*" } } ); 

another thing throw httpexception in action if token empty.

public actionresult setpassword(string token) {     if (string.isnullorempty(token))     {         throw new httpexception(404, "page not found");     }     viewbag.token = token;     return view(); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -