What ContentType for text?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi;

I am writing the output of a page directly using IHttpHandler,
IRequireSessionState and if it is a text file I set
HttpContext.Response.ContentType = "text/plain". But when it displays I get
an error telling me it's not a legal xml file.

Any ideas?
 
Hello Dave,

As for the httphandler issue, I remember that you've ever posted a similiar
issue about rendering out some certain content in httphandler and encounter
error. Is this similar to that one? Yes, the txt file's mime type is
"text/plain".

I'm not sure about your detailed code logic, here is a simple test
httphandler which flush out some txt content:

===================
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

context.Response.Write("Hello World.");

context.Response.End();
}
==================

BTW, are you using the generic handler ( the ashx ) in VS 2005? If so, this
could be causing some problem since the generic handler may add some
additional content info internally that cause any non-xml/xhtml content
display error at client browser. You can test through a typical custom
httphandler (register in the web.config <httpHandlers> section) to see
whether it works.

If you meet any further problem, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



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

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscriptions/support/default.aspx.

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



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

Still doesn't work. Here is what I am getting:

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:2634/portal/report-create.aspx?wr_id=...

XYZ Consulting Corporation Invoice Invoice
^

Here is my code:
public class ReportCreate : IHttpHandler, IRequiresSessionState
{
....
public void ProcessRequest(HttpContext context)
{
....
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

string str = GetContentType(format);
context.Response.ContentType = str; // "text/plain"
context.Response.BinaryWrite(((MemoryStream)report.GetReport()).GetBuffer());

context.Response.End();
}

Here is my web.config:
<httpHandlers>
<add verb="*" path="report-create.aspx" type="ReportCreate"/>
<add verb="*" path="report-view.aspx" type="ReportView"/>
<add verb="*" path="template-file.aspx" type="TemplateFile"/>
</httpHandlers>



Any ideas?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
Thanks for your response,

This seems abit strange. I found that you still use the aspx extension for
your custom httphandler, have you tried using a different extension such
as *.txtfile to see whether it works. Also, if convenient, you provide a
simplified repro project so that I can test on my local side.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Use a .txt extension. Some browser, IE in particular, will ignore the
"text/plain" ContentType header, as older web pages sometimes used this
header for HTML pages.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
 
Back
Top