Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the Request Variables from an ASP.NET page
    text
    copied!<p>I wrote the following function that works about 95% of the time, but I need it to work 100% (obviously):</p> <pre><code>Public Shared Function getPassedVars() As String Const keyCount As Integer = 54 ' 54 seems to be the number of parameter keys passed by default (for this web_app). ' there are more if there is a form involved (ie. from search page) Dim oParams As String = "" Try With HttpContext.Current If .Request.Params.AllKeys.Count &gt; keyCount Then For i As Integer = 0 To (.Request.Params.AllKeys.Count - (keyCount + 1)) oParams &amp;= String.Format("{0}={1}{2}", .Request.Params.Keys.Item(i), .Request.Params(i), IIf(i &lt; .Request.Params.AllKeys.Count - (keyCount + 1), ";", "")) Next End If End With Return oParams Catch ex As Exception Return Nothing End Try End Function </code></pre> <p>It scrubs the <code>Request.Params</code> object for passed variables, which are in the beginning of the array (the remaining ones are ASP parameters). I am pretty sure I've seen a different way to get these parameters, but I haven't been able to figure it out. Any suggestions?</p> <h2>EDIT</h2> <p>So it looks like I can use the <code>Request.URL.Query</code> to achieve this, I will investigate this and post back. </p> <p>Here is what I came up with:</p> <pre><code>Public Shared Function getPassedVars() As String Dim oParams As String = "" Dim qString As String = "" Dim oSplit As New List(Of String) Try With HttpContext.Current qString = .Request.Url.Query If qString.Length &gt; 0 Then 'do we have any passed variables? If qString.StartsWith("?") Then qString = qString.Remove(0, 1) 'remove leading ? from querystring if it is there oSplit.AddRange(qString.Split("&amp;")) For i As Integer = 0 To oSplit.Count - 1 oParams &amp;= String.Format("{0}{1}", oSplit.Item(i), IIf(i &lt; oSplit.Count - 1, ";", "")) Next Return oParams Else Return Nothing End If End With Catch ex As Exception Return Nothing End Try End Function </code></pre> <p>So far so good.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload