Using a querystring when debugging a web application

Using a querystring when debugging a web application

Post by Nathan Sok » Thu, 16 Aug 2007 23:39:45


Certain web pages throw an error when they do not have a querystring. This
is obviously no problem when the site is put live (just make the link to it
correct), but when debugging and the page is set as the Start Page, no
querystring is used. Is there a way to have the de *** start with a
querystring attached? (for example, by going to mypage.aspx?category=123
instead of just mypage.aspx) Thanks.
--
Nathan Sokalski
XXXX@XXXXX.COM
http://www.yqcomputer.com/
 
 
 

Using a querystring when debugging a web application

Post by Alec MacLe » Fri, 17 Aug 2007 02:47:26

How about you add a little bit of graceful handling (defensive coding) to
the page so it knows what to do when no QS is present?

In the Page_Load event handler, add somhing along the lines of:

If Me.Request.QueryString.HasKeys Then
Dim iItemID As Integer
If Me.Request.QueryString.Count > 0 Then
'We have a querystring value, as yet unknown
Dim arrK() As String = Me.Request.QueryString.AllKeys
For i As Integer = 0 To arrK.Length - 1

'Do your processing...

Next
Else
'Handle the fact that the page has no querystring values...
Me.Response.Redirect("default.aspx")
End If
Else
'Handle the fact that the page has no querystring values...
Me.Response.Redirect("default.aspx")
End If

 
 
 

Using a querystring when debugging a web application

Post by Alec MacLe » Sat, 18 Aug 2007 00:31:56

You can add the QueryString programmatically using a modification of my
earlier post (see below).

Al



<snip>

If Not Me.Request.QueryString.HasKeys Then
'Handle the fact that the page has no querystring values...
me.response.redirect(me.request.path & "?category=123")
End If


<snip>