0

I have an MVC 3 application where I want dynamic Urls which do not contain a controller or key name. A good example of this would be if I had a blog, and users add in new posts.

Say a user creates a post called

My Blog Post

I have a method that creates a url SLUG and stores it in the database with the entry, so I want the Url to be

/my-blog-post

This has no controller or key name in the url now? How do I achieve this with MVC routing? Currently I'm doing it by matching the Url with an ID like /my-blog-post_1234 and using that ID as the DB lookup key using fluent nhibernate but I'm a little lost once I remove the ID?

As I can still get the string/slug, but that means I now have to do a SQL lookup based on the string 'my-blog-post'? I have read this is not efficient and could compromise speed, and some of these titles could be pretty long.

I've heard people saying things about custom route tables? Would this help me or not? I suppose the main thing is getting the data from the database in the quickest most efficient way.

any help/pointers greatly appreciated.

4

2 に答える 2

1

MVC フレームワークは、ここでは何の助けにもなりません。スラッグでクエリを実行する必要があるため、DB でこれを行う必要があります。

クエリがテーブル スキャンを実行する必要がないことを確認するために、DB 内のこの列にインデックスがあることを確認する必要があります。

于 2012-06-10T08:29:08.987 に答える
0

あなたが本当に欲しいのは文書データベースのようです。MVC と組み合わせる。ravendb を強くお勧めします。

于 2012-06-11T02:15:33.323 に答える