Slouch
Slouch

Reputation: 667

MVC RouteConfig vs URL rewrite (in Global.asax)

Myself and a colleague had a problem that we solved in two different ways. But we don't know which is best.

We have a generic MVC page that is populated with specific data (widgets, content, etc) from a database. The user enters a specific URL (user friendly, so trying to keep the query string disguised if we can help it).

Now, the generic page has to take this URL and use it to get the corresponding data from the database to generate a specific page.

Solution 1: In the Global.asax file rewrite the URL, basically creating a Querystring that the generic controller can understand.

Soloution 2: Use the RouteConfig.cs file to force all page requests to route to the generic controller, which then reads the URL.

Any ideas,

Thanks.

Upvotes: 0

Views: 934

Answers (1)

Pinch
Pinch

Reputation: 4207

RouteConfig.cs is the cleanest way.

If you change your routing configuration, then by using Url.RouteUrl or Url.Action your generated Url's will update along with your routing configuration.

Upvotes: 1

Related Questions