views:

74

answers:

1

Hi,

Excuse my limited knoweldge here.

In the past I have used Steve Sanderson's method to HTML encode by default at runtime: http://blog.stevensanderson.com/2007/12/19/aspnet-mvc-prevent-xss-with-automatic-html-encoding/

I have a need to alter img src and a href attributes before they are spat out in the user's browser. There is a solution using JavaScript but this is not ideal for several reasons. Intercepting the compiler is not an option because of unnecessarily using Response.Write for trivial HTML.

Is there something I can do with HTTP modules or the view engine?

Any thoughts?

UPDATE: I do not need to HTML encode the attributes but I do have a need to change them.

Cheers.

+1  A: 

Use a response filter. Works with any ASP.NET project, including MVC. Should work even if you're using a different view engine, as it intercepts at a lower level.

Here's an actual example that strips whitespace:

http://www.4guysfromrolla.com/articles/120308-1.aspx

I've used this before to rewrite links before sending to the client, but I can't find the code at the moment.

Chris
Better words for what I want to do - "rewrite links". Cheers!
youwhut
A response filter was used to alter the markup before it was spat out. a HTTP module was used to kick off the response filter.
youwhut
Cool, glad it worked for ya.
Chris