Solved

How to use Request.QueryString with dynamic variables ?

Posted on 2009-05-15
6
502 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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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