Solved

context.Request.QueryString in C# handler file not working

Posted on 2016-09-14
8
48 Views
Last Modified: 2016-09-14
Hi Experts,

I was trying to get the query string from Generic handler . but the it always return null value from it . Here is my C# code

 public void ProcessRequest(HttpContext context)
        {
            int PropertyID = context.Request.QueryString["propertyid"] != null ? Convert.ToInt32(context.Request.QueryString["propertyid"].ToString()) : 1;

}

Open in new window



Jquery Code
 $.ajax({
       
        url: "Imagehandler.ashx",
        data: '{propertyid: "' + propertyid + '"}',
        
    })

Open in new window


Thanks in Advance Experts
0
Comment
Question by:karthik80c
  • 5
  • 2
8 Comments
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 41798679
The query string is part of the URL.

If you wanted to use the query string you would do:
$.ajax({
      
        url: "Imagehandler.ashx?propertyid=" + propertyid,
       
    })

Open in new window


If you wanted to use the data you would do:
string json = new StreamReader(context.Request.InputStream).ReadToEnd();

Open in new window

0
 
LVL 35

Expert Comment

by:YZlat
ID: 41798691
correct me if I am wrong, but I do not think you need single quotes:

 $.ajax({
       
        url: "Imagehandler.ashx?propertyid=%s",
        data: {propertyid: "' + propertyid + '"},
        
    })

Open in new window


or even

 $.ajax({
       
        url: "Imagehandler.ashx?propertyid=%s",
        data: {propertyid: " + propertyid + "},
        
    })

Open in new window

1
 

Author Comment

by:karthik80c
ID: 41798727
Hi Experts ,


Thanks for your valuable comments . Let me check and let u know
0
 

Author Closing Comment

by:karthik80c
ID: 41798751
Thanks its working Kyle
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:karthik80c
ID: 41798754
Hi YZlat

yes its not working friend
0
 

Author Comment

by:karthik80c
ID: 41798757
Hi Kyle,

hi could u please explain why your code working . That would be great in future . Thanks again
0
 
LVL 39

Expert Comment

by:Kyle Abrahams
ID: 41798766
Again the query string is part of the url.

so

someHandler.ashx?Part1=Var1&Part2=Var2

The Page / File = someHandler.ashx

Everything after that is data.

EG:

Request.QueryString["Part1"] == Var1
Request.QueryString["Part2"] == Var2
Request.QueryString["Part3"] == null

The data is passed in by the address and visible to users.

When you use the .data you're passing in the variables into the content stream, which has to be read using the streamreader.  Let me know if that helps.
1
 

Author Comment

by:karthik80c
ID: 41798792
Thanks Kyle and that works great
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

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