Click here to Skip to main content
15,121,564 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I am trying to use generic handler to response a message with a simple approach. In firefox browser it gives error "XML Parsing Error: no element found" , in Chrome it only shows blank page. Within another projects its working fine with same method. The problem I got with the current project only. In a solution thread I got here, someone said "Check the content of the XML file you are opening.". Here I am not using any additional file. Following is the sample code :

public void ProcessRequest(HttpContext context)
string sImgName = "";
if (!context.Request.QueryString["image"].ToString().Equals(""))
context.Response.Write("File not Exists");

I am new at using handler. Please help me with this.
Updated 22-Oct-15 22:34pm
Wombaticus 23-Oct-15 5:11am
Your code above has nothing to do with XML...?
What has the variable sImgName got to do with anything?
Why respond with "File not exists" if Request["image") is NOT = "" ?
Why not wrap the whole lot up in a try..catch block to find out just hwat the error is?
Member 11824434 23-Oct-15 6:23am
Right. my code is nothing to do with XML, but I am getting this error only in firefox and bank page in ie and chrome. It didn't got any difference whatever I have written inside here. I tried with the breakpoint, debug pointer is not coming here in handler.

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");

This code also returns same error.
Wombaticus 23-Oct-15 6:40am
How can that possibly return an error? Are you trying to read that response as XML? You've sent plain text, which it is there. But when you do want to return XML you should set the response.contenttype to "text/xml"
Member 11824434 23-Oct-15 6:48am
There is nothing to do with XML. I just need to use handler for a plain response. That is why I am using "text/plain". This code is running well in another projects where I am sending text, images or documents as response.
Wombaticus 23-Oct-15 7:01am
Well what is the error? It can't be the XML Parsing error in your title. It's more likely a javascript error in a calling page, but there is not enough information here to know.
Member 11824434 23-Oct-15 7:46am
There is no javascript error either. I tried it to redirect from a new aspx page. Nothing changed. Could it be a configuration problem. Do I need to add/edit anything to web.config.
Thanks for your replies Wombaticus. I need to solve this. I am working on this since 4 days ago. Still not succeeded.
Wombaticus 23-Oct-15 8:01am
Well a redirect won't help - generic handlers don't produce a response that will show up - you'll just get a blank screen. You either need to read the response in JavaScript or, if your handler does something like write to a file or send an email you can test the response that way. But I'm afraid without seeing much more of your code there's not much to go on...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900