by garyg
10. April 2010 10:01
Figured I'd share something I found valuable. Did you ever make a call to a request level plug-in in a Visual Studio 2008 WebTest and get multiple calls to the same plug-in because of a 302 redirect? Well I did and took me a little bit to find out a way to prevent it.
When you are making the call in your code, decide if it should run based on IsRedirectFollow property (http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.webtesting.webtestrequest.isredirectfollow(VS.80).aspx)
As an example:
1: namespace MyAppTests
2: {
3: public class GetSomethingPlease: WebTestRequestPlugin
4: {
5:
6: public override void PostRequest(object sender, PostRequestEventArgs e)
7: {
8: if (e.Request.IsRedirectFollow == false) //only want to run this on on a primary, not a redirect
9: {
10: //do something here
11: }
12: }
13: }
14: }
15:
Anyway, I hope this helps someone else a little further along. It works in VS2008 and VS2010 as well. I'm sure there could be a more efficient way, but this worked in a pinch ;-)