Solved

How to use Request.QueryString with dynamic variables ?

Posted on 2009-05-15
6
500 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

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 500 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Format Transaction Number 19 50
asp.net, radiobuttonlist, c# 3 69
VB.Net Developer - Suggestions for Web Programming OnLine Learning 4 61
Convert a string to date 4 40
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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