Pharao2k
Pharao2k

Reputation: 695

Access static content from area w/o "Areas" in url

I am currently working on a web app with a small web page on the root level and several (more complex) web pages in areas. All area-based web pages have static content that is independant of each other, so each of them has it's own content folder. Unfortunately the resulting url's for the static content contains the string "Areas", for example

http://myappurl/Areas/MyArea1/Images/myFile.png

Since Areas are a technical implementation detail and nothing that the user should know (or care about), they do not belong in the url. How can I fix that? I don't want to create another root-level directory for each area (would be confusing and error-prone), but I don't really understand how I could modify routing to allow this otherwise. Help would be appreciated :)

Upvotes: 0

Views: 750

Answers (1)

smartcaveman
smartcaveman

Reputation: 42256

By default, ASP.NET does not handle requests to .png files.

Scott Hanselman has an article that explains how to change this functionality. Link: Back to Basics: Dynamic Image Generation, ASP.NET Controllers, Routing, IHttpHandlers, and runAllManagedModulesForAllRequests.

If you follow the instructions there, then you will be able to gain control of how requests to all png files are routed. So, you get to define routes the same way for the file nested within the area as you do for any other View/JSON/XML. The trick is then to set the appropriate content type and render the image as a filestream.

Upvotes: 1

Related Questions