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.

Recommended Answers

All 2 Replies

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)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.