views:

94

answers:

5

I'm working with ASP.NET MVC but this really applies to any MVC framework. I understand that one of the benefits of an MVC framework is the construction of "pretty" urls. I have kept my small application simple thus far and most routes use the normal convention of: controller/action/id. However, now I've created a simple page that will redirect to an action based on the query string parameter given:

mysite.com/visitors/lookup?signAction=signin
or
mysite.com/visitors/lookup?signAction=signout

Coming from Web Forms, this construction is natural and very common, but I'm afraid I'm not realizing the benefits of pretty urls here.

For my example, would it be best to create a custom route or keep it as-is? What is the general rule of thumb for when custom routes end and query string parameters begin?

A: 

We're going with /session/new => login form /session/create POST /session/destroy DELETE logout

Tass
+1  A: 

If you set up your routes properly, it can be:

mysite.com/visitors/lookup/signin

or simply

mysite.com/visitors/signin

You'll have to decide how far to go with it, but I think you can do better than your examples without monkeying much with the routing structure.

Robert Harvey
+1  A: 

Honestly, I want to say it depends on your preference, which is the great thing about it. There is no rule of thumb when it comes to making anything. Well, maybe when it comes to performance, but in this case, there is no performance change to worry about. Personally, I'd say create a new route. It's not too difficult and like you said, it's pretty URLs. Also, another thing to consider would maybe be a hidden value. I'm not fully sure of your code layout, but if you had a hidden input of signaction and the value changes, then you could just do a Request.Form["signaction"] to get the value. Hope this helps.

XstreamINsanity
+3  A: 

Firstly I wouldn't say this has got anything to do with MVC. Pretty urls can/should be used pretty much anywhere.

Secondly, it really depends on how you're using your urls. But the big idea is that 'pretty urls' are NOT a replacement for query parameters.

Like for example, your

mysite.com/visitors/lookup?signAction=signin

Could/should? easily translate into

mysite.com/signin

Basically the idea behind pretty urls two fold.

Their primary purpose is that many of them should be MEMORIZABLE. The pretty urls idea came out of things like amazon's 2000+ character monstrosities.

Their secondary purpose is SEO. However as of late many developers have started forgetting this and are putting all sorts of junk back into their urls.

But what I'm trying to say is that

mysite.com/articles/page/2

is essentially no prettier than

mysite.com/articles?page=2
Swizec Teller
A: 

The main advantage to URL routing to "pretty URLs" is search engine optimization and permalinking content. For a logout action, neither of these are really applicable. It's merely an aesthetic decision in this case.

treefrog