Solved

How to use Request.QueryString with dynamic variables ?

Posted on 2009-05-15
6
496 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now