Last post Apr 06, 2011 12:01 AM by niravpatel
Apr 04, 2011 08:36 PM|niravpatel|LINK
What I would like to do is every url that is rendered as,
http://www.site.com/images, I would like to change it to
Also I was wondering about what to do with the urls that are in CSS where it's mentioned as "../images/background.png" to something like
Is this possible? If so then how do I proceed and where do I start from?
I am using IIS7. ASP.NET with .Net Framework 4. Not using MVC.
Any help or nudge in a write direction with some sample code would be appreciated.
Apr 05, 2011 05:57 PM|rstrahl|LINK
You can use an ASP.NET Response Filter to filter the final output of a request. Filters basically while the Response is being streamed out.
I wrote an article about capturing and transforming Response output some time ago that might be helpful to you. It includes a class that has the abililty to easily capture the entire Response and optionally transform it.
Hope this helps,
+++ Rick ---
Apr 05, 2011 07:27 PM|niravpatel|LINK
Thanks Rick. That is certainly helpful. I am going to go ahead and see if I can manage to make it work the way I need to make it work.
I assume there is a lot of performance penalty for doing a thing like this, also with any HttpModule or Handler.
Is there a more efficient way of doing this?
Apr 05, 2011 09:11 PM|rstrahl|LINK
Yes there's some overhead in this especially if you look at every response. But maybe you can filter just by folder or some other criterion so not all links are automatically filtered.
Nope - there's no more efficient way through .NET. You can write an ISAPI Filter in unmanaged code that might have better perf, but in the end you have to filter the output before IIS sends in some way which means you have to fire user code in order to do
the transformation and re-write the output stream.
The other alternative is to use a dynamic URL in your pages - rather than hardcoding the image URL use some dynamic value:
<img src="<%= App.Configuration.ImageServerUrl %>/images/someimgage.gif" />
or a full function that creates the whole Image tag altogether
<%= ImageConfig.ImageServerUrl("~/images/someimgage.gif") %>
The former might be fairly easy to do with a little bit of Replace in Files of a project and that will work as long as the content is in ASPX (or similiarily Razor) files. And either approach would be much more efficient than post request filtering.
Before you discount filtering however, you should test it - the overhead on small pages is pretty small and depending on how high your server load is it might not have much of an impact at all. Don't assume it'll be too slow :-)
Apr 06, 2011 12:01 AM|niravpatel|LINK
Thanks again Rick.
I understand what you are saying and I was more worried about URLs coming from CSS than anything else. Those are my main concern. To be honest every image has it's url coming from the CSS, infact they are DIVs and not so much as images.
Any suggestions there? There are defined as,