Can MVC handle regular URL path requests, too?
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 specifi开发者_JS百科ed 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!
This should work without you doing anything - static files are not processed by the routing engine.
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
Take a look at the @Url.Content() helper method.
Url.Content("~Content/Images/Geography/Asia/Japan/TokyoAtNight.jpg")
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.
精彩评论