craigmoliver
craigmoliver

Reputation: 6562

What's the trouble with my ASP.NET MVC route?

I have some routes in my ASP.NET MVC application that handle redirecting of old urls. The URL I'm redirecting is:

contentSpanishContentList.aspx

Here's the route:

routes.MapRoute("RedirectLegacyContent1",
                "content{contentUri}.aspx",
                new { controller = "Redirect", action = "Content", contentUri = string.Empty, contentId = 0 });

The problem is it comes up as not found. I figured out that the problem is (in bold) contentSpanish*Content*List.aspx. What should I do to make this route work with this case?

Upvotes: 0

Views: 109

Answers (2)

Robert Koritnik
Robert Koritnik

Reputation: 105019

Two solutions

  1. Rename your pages to not include the same constant string (in your case it's the word content).
  2. Write a custom route that's able to parse your requests - all you'll have to override is the GetRouteData method. And if you're planning to only use this route for incoming requests (not generating any URLs in your views to point to any of these pages ie. using Url.Action or Html.ActionLink) then the easiest way would be to generate something like a RegExRoute which would be easy to write and also easy to resolve these kind of requests.

The fist one is simple, the second is universal.

Upvotes: 1

Haacked
Haacked

Reputation: 59001

  1. Use Fiddler to look at what's happening. Is the 404 happening on the first request? Or is it happening after the redirect?

  2. Install the RouteDebugger package and see what it tells you.

Upvotes: 1

Related Questions