开发者

HTTPmodule - Replacing Markup

I have created an HTTPModule that is being called for every request to my website. Inside the module I have created my own filter wrapper for HTTPApplication.Context.Response.Filter that allows me to manipulate the markup just before it is sent back to the client.

The idea here is that I am going to search for certain words/phrases and replace them with the same word/phrase in a given language which will be stored in a database.

One of the开发者_运维技巧 words I am trying to replace is "Password". The problem is that there are controls in the markup called _ctl122_txtPassword and when I am in my filter I am literally just doing string manipulation (search/replace/etc.) so the control name gets renamed to _ctl122_txtTranslation which breaks all kinds of things.

So I dont want to replace matches in this: <input type="password" style="width: 200px;" class="formfield" id="_ctl22_txtPassword" name="_ctl22:txtPassword">

but I do want to replace matches in this: <td align="right" class="formlabel">Password:</td>

I have tried a few RegEx solutions but I am far from a RegEx ninja so this could be the way to go but I just dont know them well enough.

The only other alternative I have tried is actually replacing the string '>Password'.

Thanks in advance for the help.


Due to the nature of HTML, it is kind of hard to write a regex that will handle every case.

You could use this as a starting point

http://snook.ca/archives/active_server_pages/vbscript_code_t

A better solution may be to use a HTML parsing tool (Html Agility Pack)

http://social.msdn.microsoft.com/Forums/en/regexp/thread/3b0a595b-cd09-446f-bbcb-d826511c364e

If i was going to do this (sounds like a multi-language site), i would probably use resource files

Or maybe have defined macro boundaries, so that my regex could look for things easily.

eg with @@'s

<td align="right" class="formlabel">@@Password@@:</td>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜