views:

261

answers:

2

Let me say I have a route/action for showing content pages like this:

/Page/{slug}

where {slug} can be anything that a visitor types in but if left empty it defaults to "Default".

I have my route definition handle the case where {slug} is empty or Default or anything else, so that is setup fine.

Now, what do you do in those cases where the requested slug (e.g. Page) does not exist?

Someone requested /Page/xyz for instance and XYZ does not exist in my datastore.

1) Should I issue 404 (if so, how? My options: a) redirect to default 404 page; b) no 404 response, just a friendly error message?)

2) Should I automatically redirect to default? If so, do I have to issue 302, 301 or what?

I understand this is debatable but still would like some opinions about it on what are the best prectices. Also please provide few lines of code of how would you go implementing it in ASP.NET MVC controller actions.

+1  A: 

see this topic, it contains all required info for your case

zihotki
+1  A: 

@zihotki has linked a good page for understanding what kind of response codes to send. To send them in ASP.NET MVC, you will want to instantiate an error controller in your error handling code and your response from there should set the HttpResponse.StatusCode appropriately.

NickLarsen