ASP.NET MVC static-asset aides/practices

Posted by shannon on Stack Overflow See other posts from Stack Overflow or by shannon
Published on 2011-02-26T23:09:14Z Indexed on 2011/02/26 23:25 UTC
Read the original article Hit count: 304

Filed under:
|
|

I want to keep assets that are only used by one view in a view-specific folder, so my Search.aspx properly finds images/*.jpg, and helps me maintain my convention:

~/Areas/Candidate/Views/Job/Search.aspx ->
~/Assets/Candidate/Job/Search/images/*.jpg

Perhaps with the ability to easily reference controller- or area-common assets manually or automatically:

~/Assets/Candidate/Job/images/*.jpg
~/Assets/Candidate/images/*.jpg

If you wonder why I'm doing this, then speak up; I'm probably missing something. But here's why:

I don't want stale static assets sitting in my ASP.NET MVC projects, which I expect to be an automatic outcome of the ~/Assets/Images folder: i.e. As a shared asset loses its last reference-count, who knows to delete it, especially with it being so difficult to trace content link validity in MVC projects?

How do you, personally, do this? I can imagine, for example:

  1. Implement HtmlHelper extension methods for URL-generation.
  2. Extending ViewPage and ViewMasterPage with URL-generation methods.
  3. Implementing an inbound request filter to search related folders for static assets.

and, are there good libraries out there for this? For example, something that also automatically appends timestamps for .JS and .CSS files, writes the / tags for me, and maybe even that allows me to inject includes in the head section from outside head code?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc