0

Is there a way in C# to get a value that is normally passed in the url string into the variable while debugging??

Normally this is the string...
http://server/foldertest/Page.aspx?sel=ss

But when using "start debugging" I have the url without the form variable that is passed from another server but need to get the variable into the debugging application in order to test.
http://server/foldertest/Page.aspx

It looks to be part of the request.form but I'm not sure where or how to get the "ss" into the collection while in debug mode before it bombs. Not where in the code but where in the collection and how.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sknake
0

From what I've found you can't change a query string's collection values since they originate in/from the url.
But you can cheat the system a bit by inserting a response.redirect into code to get the variables you need for testing......

Response.Redirect("http://server/foldertest/Page.aspx?sel=ss)

0

Override the OnInit() method of your page:

protected override void OnInit(EventArgs e)
    {
#if DEBUG
      if (string.Compare(Request.QueryString["sel"], "ss", true) != 0)
      {
        Response.Redirect(@"http://server/foldertest/Page.aspx?sel=ss");
      }
#endif
      base.OnInit(e);
    }

That should run early enough in the page life cycle to keep your page from bombing out. You could also set your "Start Page" to another page and navigate to the URL manually.

Edited by sknake: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.