Solved

Receive name of variable not variable content when using Request.QueryString["var1"]

Posted on 2016-08-27
7
61 Views
Last Modified: 2016-09-01
Here is a sample of the Asp.net Webform that is requesting the variable


.NET Webform

 protected void Page_Load(object sender, EventArgs e)
        {
            var var1 = Request.QueryString["var1"];
 

            string testthree = var1

Open in new window


'''''''''''''''''''''''''
Here is a copy of the VBA code that is sending the variable


VBA Macro

''Dim oXMLDoc, oXMLHTTP

     Dim strEnvelope As String

       Dim response As String

       Dim emailvalues As String

      Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")

    Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
       

    strEnvelope = "test"  
     

   emailvalues = ("var1=strEnvelope")
    
 ''Call oXMLHTTP.Open("POST", "http://server/WebForm1.aspx?var1=strEnvelope", False)

   Call oXMLHTTP.Open("POST", "http://server/WebForm1.aspx?var1=strEnvelope", False)     
   Call oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")

   Call oXMLHTTP.Send(strEnvelope)

   Dim szResponse: szResponse = oXMLHTTP.responseText

    Call oXMLDoc.LoadXML(szResponse)

     If (oXMLDoc.parseError.ErrorCode <> 0) Then

       'call msgbox("ERROR")

        'response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason

        'call msgbox(oXMLDoc.parseError.reason)

    Else

        'response = oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text

        MsgBox (oXMLHTTP.Status)

    End If

MsgBox (oXMLHTTP.Status)

Open in new window

0
Comment
Question by:Member_2_7964962
  • 4
  • 3
7 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 41773132
You're sending a literal value to the page which is the variable name: "http://server/WebForm1.aspx?var1=strEnvelope"

Simplest solution (for testing at least) is to change this to: "http://server/WebForm1.aspx?var1=" & strEnvelope

When you get this to work, you will want to consider URL-encoding the variable in case the actual value contains any special characters not allowed in a URL.

Note by the way that you are using a POST method but are sending this variable in the query-string which is normally done for a GET request. It's possible to mix them as you do but maybe you need to change it, nowadays on a lot of web servers there is a severe restriction on query-string length for security reasons.
1
 

Author Comment

by:Member_2_7964962
ID: 41773858
Thanks for your help, I will give this a try when I am in the office.
0
 

Author Comment

by:Member_2_7964962
ID: 41780188
What would be the best way to pass multiple parameters in the string below? For example, var2, and var3

http://server/WebForm1.aspx?var1=" & strEnvelope
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 35

Expert Comment

by:Robert Schutt
ID: 41780330
Something like this:

... "http://server/WebForm1.aspx?var1=" & strEnvelope & "&var2=" & strVar2 & "&var3=" & strVar3

Assuming you have variables strVar2 and strVar3 filled with strings like you have strEnvelope.

Note that & is used both as a seperator in the querystring (after the initial question mark) as well as an operator in the VBA language to concatenate strings.

It also may become more important now you are adding extra variables to think about the other 2 remarks in my first comment.
1
 

Author Comment

by:Member_2_7964962
ID: 41780340
For sure, but not sure how to accomplish this yet. In regards to the remarks in your first comment, would this make the whole process that I am trying to accomplish easier. Some of the values that I am passing our Outlook email items such as senders name, attachments etc.

 I am passing the parameters to the following Response.Write link.

The Class is identified below the Response.Write code below. Are you familiar with passing several parameters using Response.Write, and receiving them using HttpPost? See Example below.


             Response.Write(Class1.HttpPost("http://172.23.0.106:7722/WebService1.asmx?op=MyMethod", test));


     public class Class1
     {
   

    public static string Errors { get; set; }

     public static string HttpPost(string URI, string Parameters)

     {
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 41780372
No, it wouldn't make it easier, but it would make it safer and more robust.

The question in the second part of that last post makes little sense to me. You should probably gather some more info and ask a new (related) question. Your audience here will be very limited (possibly just me) now that the question is closed.
0
 

Author Comment

by:Member_2_7964962
ID: 41780392
Thank you, agreed.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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