IHttpHandler problem

G

Guest

Hi;

I just wrote my first IHttpHandler and am having a problem. If the content
type is "text/html" then the below code works fine. But if it's "text/plain"
then my browser gets:
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource
'http://localhost:3179/portal/ShowReport.aspx'. Line 1...

hi there
^

url is: http://localhost:3179/portal/ShowReport.aspx

code (App_Code\ShowReport.cs) is:
using System.Web;

/// <summary>
/// Summary description for ShowReport
/// </summary>
public class ShowReport : IHttpHandler
{
public ShowReport()
{
}

#region IHttpHandler Members

public bool IsReusable
{
get { return false; }
}

public void ProcessRequest(HttpContext context)
{

context.Response.ContentType = "text/plain";
context.Response.Write("hi there");
}

#endregion
}

web.config is:
<httpHandlers>
<add verb="*" path="ShowReport.aspx" type="ShowReport"/>
</httpHandlers>

???
 
S

Steven Cheng[MSFT]

Hi Dave,

I think the problem is that the response stream has not be eneded after you
finishing write out the content. then, the runtime may add some additional
http headers which cause the client browser fail to parse it. You can call
the response.End() to end the response stream after you finishing the
content outputing. e.g:

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

context.Response.End();

}

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top