Today I had to add a new HttpModule to A LOT of web.configs. Adding it manually would be too tedious, so I had to figure out how to search for a single line in Visual Studio 2010 and replace it with two lines of text. If I could only find a way to search for some text, and replace it with several lines of text!
Google turned up some hints about the Regex search, but no apparent solutions. After playing around a bit with the regex search in Visual studio, I found that it supports multiline text in both the search and replace strings.
When you're using "Find and Replace" in Visual Studio you can enable Regular Expressions, under "Find options", as shown in the screenshot. The regular expressions let you represent newlines in the search or replace fields, by using a \n. Cool! I've included an example below the image.
But beware, when you enable regular expressions you need to escape special characters, in my case < and >, with a backslash. Your "Find" statement will be interpreted as a regular expression. Check out the MSDN page on regular expressions in Visual Studio to learn more about which characters are special and which are not.
Update Sep. 2012: This post deals with Visual Studio 2010. Regular expressions have changed in VS 2012, as you'll see from the link above. See the comments on this post for a new example of multiline search and replace for both VS 2010 and VS 2012.
Software security blog by André N. Klingsheim, who's learning to love .NET and Microsoft servers.
Disclaimer
Any opinions expressed here are my own and not necessarily those of my employer (I'm self-employed).
Subscribe to:
Posts (Atom)
Copyright notice
© André N. Klingsheim and www.dotnetnoob.com, 2009-2018. Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to André N. Klingsheim and www.dotnetnoob.com with appropriate and specific direction to the original content.
Read other popular posts
-
Microsoft's widely used e-mail service Hotmail was recently overhauled and rebranded Outlook.com. One of the less known services they pr...
-
Security headers in an HTTP response There are many things to consider when securing a web application but a definite "quick win&qu...
-
OWASP recently released their Top Ten 2013 list of web application vulnerabilities. If you compare the list to the 2010 version you’ll see t...
-
I just read an interesting article on the Naked Security blog: New Android Market web store could open backdoor for phone hackers . Turns ou...
-
Yesterday I was playing around with the validateIntegratedModeConfiguration="true" setting on IIS 7.5. To my surprise I got an ...
-
If you work in an environment where several people fiddle around on the same servers, every once in a while you'll get the message "...
-
Windows Identity Foundation (WIF) is vulnerable to replay of security tokens in its default configuration. The " Replay Detection "...
-
In a production environment, users should not be presented the default ASP.NET error pages. Instead they should be offered clean, understand...
-
I guess it was long overdue for me to follow up on my Hardening Windows Server 2003 SSL/TLS configuration and Windows server 2003 vs 20...
-
Guids are used extensively throughout Microsoft systems and developers tend to turn to Guid.NewGuid() whenever they need to create a value ...