views:

39

answers:

2

I want to use URL such as /Image/sample.png
I create route, but it does not work, it say "The resource cannot be found"
What is the problem? (action GetImage is in controller home)

routes.MapRoute("Image",
  "Image/{id}",
  new { controller = "Home", action = "GetImage", id = "" });
A: 

The ASP.NET MVC Routing is looking for an Action named sample.png in controller named Images and not finding it (which make scence).

You should use an alternerive image routing or return in from an Action

tsinik
and how can i make this?
kusanagi
see Hightechrider answer.
tsinik
+1  A: 

Try

routes.MapRoute("Image", "Image/{id}.{format}", new { controller = "Home", action = "GetImage", id = "", format = format });

See http://weblogs.asp.net/scottgu/archive/2008/04/16/asp-net-mvc-source-refresh-preview.aspx

And make sure you don't have some earlier route, e.g. /controller/action which is 'stealing' the request.

Hightechrider