Solved

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

Posted on 2016-09-14
8
158 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
[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
  • 5
  • 2
8 Comments
 
LVL 40

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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

Author Closing Comment

by:karthik80c
ID: 41798751
Thanks its working Kyle
0
 

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 40

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

752 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