Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use Request.QueryString with dynamic variables ?

Posted on 2009-05-15
6
Medium Priority
?
511 Views
Last Modified: 2013-11-07
HI

A web catalog uses local variables in order to filter and index products but sometimes would be necessary create dynamically values using a query string like: catalog.aspx?var1=val1&var2=val2...., and sometimes just will be: catalog.aspx (without any query string)

How could I implement dynamic variables in order to avoid errors in case they doesn´t exist ?

Thanks.
0
Comment
Question by:dimensionav
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 24393099
Hi dimensionav,
>>..How could I implement dynamic variables in order to avoid errors in case they doesn´t exist ?
It sound like pre-caution step to avoid any malicious input from user during the application accessing the dynamic variables that created. How is your existing code flow look like and any errors that return at the moment during the missing of dynamic variable's existances?
0
 

Author Comment

by:dimensionav
ID: 24393179
HI

I have the attached code at the very top of script area but when there´s nothing to get from query string, I got an error: REQUEST NOT AVAILABLE IN THIS CONTEXT.

And as you said, how to protect from malicious code?
Thanks.
    Dim GetIdCategoria As String = (Request.QueryString("idcategoria")).Trim
    Dim GetIdSubcategoria As String = (Request.QueryString("subcategoria")).Trim
    Dim GetBusqueda As String = (Request.QueryString("busqueda")).Trim

Open in new window

0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 24393288
Hi dimensionav,
You can write a custom function to cater this malicious input, you can enhance it on your need.
eg:
Dim GetIdCategoria As String = GetQueryParams(Request.QueryString("idcategoria"))

 Function GetQueryParams(ByVal str As String, Optional ByVal strBlank As String = "") As String
        Dim s As String = strBlank
        If Not String.IsNullOrEmpty(str) Then
            s = str.ToString.Trim
        End If

        Return s
    End Function
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dimensionav
ID: 24393454
if the form doesn´t receive any query string variable the code is still giving the same error.
I have tried to call the file as catalogo.aspx

Thanks.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 24393516
Hi dimensionav,
The posted code is working fine under test site. Do you apply it under any CMS application?
Try check if this article helps:
http://cosier.wordpress.com/2008/02/15/request-is-not-available-in-this-context-request-not-available-at-application_start-in-iis7/
0
 
LVL 7

Accepted Solution

by:
ajolly earned 2000 total points
ID: 24401078
try this:
Dim GetIdCategoria As String =""
If Not IsNothing Request.QueryString("idcategoria") then
    GetIdCategoria = Request.QueryString("idcategoria")
End If

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question