• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

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

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
karthik80c
Asked:
karthik80c
  • 5
  • 2
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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
 
YZlatCommented:
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
 
karthik80cAuthor Commented:
Hi Experts ,


Thanks for your valuable comments . Let me check and let u know
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
karthik80cAuthor Commented:
Thanks its working Kyle
0
 
karthik80cAuthor Commented:
Hi YZlat

yes its not working friend
0
 
karthik80cAuthor Commented:
Hi Kyle,

hi could u please explain why your code working . That would be great in future . Thanks again
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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
 
karthik80cAuthor Commented:
Thanks Kyle and that works great
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now