Solved

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

Posted on 2016-09-14
8
219 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

630 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