How do I mix short URLs and regular URLs in ASP.NET MVC? -
i have site normal, default route , several controllers. distribute "short url" links can link home/index action. example, can do
- /mysite - takes home/index default
- /mysite/somecontroller/someaction - takes specified controller/action default
but do:
/mysite/someid - takes home/index id param supplied.
i can add "shorturl" route , distribute url "/mysite/shorturl/someid", there other way use "id-only" url 1 above?
the problem you've got doing following ambiguous:
/mysite/someid /mysite/somecontroller how expect able differentiate between two? if don't mind second being impossible (i.e. happy specifying action when specify controller), try this:
routes.maproute( "shorturl", "{id}", new { controller = "home", action = "index", id = url.optionalparameter } ); routes.maproute( "default", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = url.optionalparameter } ); requesting /mysite/someid should take same action mysite/home/index/someid.
if need able specify either , id or controller (with default action), following (also using above routing):
public class homecontroller : controller { public actionresult index(string id) { // if id represents something, show something. if (idmatchessomeresource(id)) { // return view(); } // otherwise, treat request controller. else { return redirecttoaction("index", id); } } }
Comments
Post a Comment