Solved

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

Posted on 2016-09-14
8
64 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 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
 

Author Closing Comment

by:karthik80c
ID: 41798751
Thanks its working Kyle
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.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular - "nest" service calls? 18 22
Sorting a string 1 10
Video Player 2017 5 8
Gridview alignment 1 8
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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now