1

ASP.NET MVC newbie question:

I've set up a MVC site, with a few controllers. Now my site also has a lot of content files, which are stored in a network of subfolders within my web site, and I need to be able to access them directly, e.g.

http://mydomain.com/Content/Images/Geography/Asia/Japan/TokyoAtNight.jpg

Is there a way to make this a direct pass-through to the content folder, as specified by the path, or do I have to make a Content controller that interprets the rest of the URL and returns the file as some kind of ActionResult? Bear in mind, of course, that there will be lots of different content types, not just JPEGs.

Thanks for your help!

Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
  • You can use custom routing: http://stackoverflow.com/questions/2982140/asp-net-mvc-custom-routing-long-custom-route-not-clicking-in-my-head – Kiril Mar 03 '11 at 08:26

4 Answers4

4

This should work without you doing anything - static files are not processed by the routing engine.

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
  • I agree. The other answers and comments seem to have misunderstood the question. :) – bzlm Mar 03 '11 at 15:31
2

You want to look into Routing, and IgnoreRoute specifically. Here are a couple of places to start.

Asp.Net Routing: How do I ignore multiple wildcard routes?

http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs

Community
  • 1
  • 1
glomad
  • 5,539
  • 2
  • 24
  • 38
0

Take a look at the @Url.Content() helper method.

Url.Content("~Content/Images/Geography/Asia/Japan/TokyoAtNight.jpg")
Ryan Tofteland
  • 913
  • 6
  • 11
0

Yes.

The IRouteHandler and the route registration in your global.asax is your extensibility point for configuring how MVC handles url paths.

However, by default ASP.NET MVC will allow you to access image files directly, without any additional configuration.

smartcaveman
  • 41,281
  • 29
  • 127
  • 212