c# - Routing and Controller Actions - Optional Data -


i created route in asp.net mvc application looks this:

routes.maproute(     "articleroute",     "{year}/{month}/{day}/{articleid}/{displayname}",     new { controller = "article", action = "details" } ); 

i want route blog post article.

example: http://www.foobar.com/2010/01/01/123456789/the-name-of-the-article

in details controller action want permanent redirect if year, month, date , display name not correct. want know best way write details() controller method.

the field required articleid. if have article id database have article date , name are.

i want know how controller method should like. pass in of values method or use routedata them?

public actionresult details(int articleid, string displayname) {     var article = */snip*/;      int articleyear = routedata.values["year"];     // etc.     datetime articledate = new datetime(articleyear, articlemonth, articleday);      string realdisplayname = article.name.toseostring();      if( displayname != realdisplayname || article.date != articledate)         // permanent redirect actual article      return view(); } 

or

public actionresult(int year, int month, int day, int articleid, string displayname) {     var article = /*snip*/;      datetime articledate = new datetime(year, month, day);      string realdisplayname = article.name.toseostring();      if( displayname != realdisplayname || article.date != articledate )         // permanent redirect actual article      return view(); } 

i think both technically work, better way?

also: if there other flaws in doing feel free point them out.

i prefer restful url s query strings because clear, can read users , seo friendly.

in case if want url .../2010/01/01/123456789/the-name-of-the-article second method better one.

but think there's no need use data/month if using article id in url.

applications wordpress use /year/month/title format because if give title of article takes more time query database. year , month can speed db querying since can narrow down results , title search on result set.

i think should use route .../123456789/the-name-of-the-article

see url of question routing , controller actions - optional data in here question title used seo purposes.

if want design pure restful url should .../articles/the-name-of-the-article

i create urls there many ways optimize db querying (like hashing) , love pure rest.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -