473,795 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What ContentType for text?

Hi;

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

Any ideas?

--
thanks - dave
david_at_windwa rd_dot_net
http://www.windwardreports.com

Jul 20 '06 #1
5 8602
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.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );

context.Respons e.Write("Hello World.");

context.Respons e.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 <httpHandlersse ction) 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/subscripti...ult.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/subscripti...t/default.aspx.

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

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

Jul 21 '06 #2
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, IRequiresSessio nState
{
....
public void ProcessRequest( HttpContext context)
{
....
context.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );

string str = GetContentType( format);
context.Respons e.ContentType = str; // "text/plain"
context.Respons e.BinaryWrite(( (MemoryStream)r eport.GetReport ()).GetBuffer() );

context.Respons e.End();
}

Here is my web.config:
<httpHandlers >
<add verb="*" path="report-create.aspx" type="ReportCre ate"/>
<add verb="*" path="report-view.aspx" type="ReportVie w"/>
<add verb="*" path="template-file.aspx" type="TemplateF ile"/>
</httpHandlers>

Any ideas?

--
thanks - dave
david_at_windwa rd_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Steven Cheng[MSFT]" wrote:
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.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );

context.Respons e.Write("Hello World.");

context.Respons e.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 <httpHandlersse ction) 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/subscripti...ult.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/subscripti...t/default.aspx.

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

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

Jul 24 '06 #3
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.

Jul 24 '06 #4
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.
"David Thielen" <th*****@nospam .nospamwrote in message
news:D8******** *************** ***********@mic rosoft.com...
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, IRequiresSessio nState
{
...
public void ProcessRequest( HttpContext context)
{
...
context.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );

string str = GetContentType( format);
context.Respons e.ContentType = str; // "text/plain"
context.Respons e.BinaryWrite(( (MemoryStream)r eport.GetReport ()).GetBuffer() );

context.Respons e.End();
}

Here is my web.config:
<httpHandlers >
<add verb="*" path="report-create.aspx" type="ReportCre ate"/>
<add verb="*" path="report-view.aspx" type="ReportVie w"/>
<add verb="*" path="template-file.aspx" type="TemplateF ile"/>
</httpHandlers>

Any ideas?

--
thanks - dave
david_at_windwa rd_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Steven Cheng[MSFT]" wrote:
>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.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );

context.Respons e.Write("Hello World.");

context.Respons e.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 <httpHandlersse ction) 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/subscripti...ult.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
approximatel y
2 business days

as the support professional working with you may need further
investigatio n
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/subscripti...t/default.aspx.

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

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


Jul 24 '06 #5
that was it - thanks

--
thanks - dave
david_at_windwa rd_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Kevin Spencer" wrote:
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.
"David Thielen" <th*****@nospam .nospamwrote in message
news:D8******** *************** ***********@mic rosoft.com...
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, IRequiresSessio nState
{
...
public void ProcessRequest( HttpContext context)
{
...
context.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );

string str = GetContentType( format);
context.Respons e.ContentType = str; // "text/plain"
context.Respons e.BinaryWrite(( (MemoryStream)r eport.GetReport ()).GetBuffer() );

context.Respons e.End();
}

Here is my web.config:
<httpHandlers >
<add verb="*" path="report-create.aspx" type="ReportCre ate"/>
<add verb="*" path="report-view.aspx" type="ReportVie w"/>
<add verb="*" path="template-file.aspx" type="TemplateF ile"/>
</httpHandlers>

Any ideas?

--
thanks - dave
david_at_windwa rd_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Steven Cheng[MSFT]" wrote:
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.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );

context.Respons e.Write("Hello World.");

context.Respons e.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 <httpHandlersse ction) 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/subscripti...ult.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/subscripti...t/default.aspx.

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

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



Aug 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1817
by: Kamyk | last post by:
Hello all! I have the following problem. I have both text content and image content of the web page created in ASP language. How to do combine these two different types on the page. When I use one of the type: Response.ContentType="text/HTML", I cannot make the image shown on the page. The image is a string of confused chars. Using second type:
3
25048
by: Webgour | last post by:
How do you reproduce this vbscript in C# <% Response.ContentType = "text/plain" response.write "This is text type" %>
3
6789
by: MJ | last post by:
I'm trying to stream the contenttype of "application/x-java-jnlp-file" via asp.net/c#, but the client only sees it as a plain text file. Example: Response.Clear(); Response.ClearHeader(); Response.Contenttype = "application/x-java-jnlp-file" Response.Write(--- jnlp file stuff ---) Response.End();
8
2040
by: Bryan Glennon | last post by:
I have an aspx page. If I set the Response.ContentType = "application/voicexml+xml" then when I load browse to the page it downloads the file and opens .Net Studio to allow me to edit it. It should just display in my browser (as it does if I don't set the ContentType). I have appropriate MIME types set up in IIS (.vxml --> application/voicexml+xml). What am I doing wrong here? And more important, how can I fix it?
8
2700
by: DanB | last post by:
This is probably soooo simple but I can't seem to get it. I have a text file that I want users to download via a web page. I want the file to be saved to a default folder (or one that they choose) on the users / client file system. I have toyed with a Self-Extracting zip file but the contents of my zip file changes each time it is downloaded so that invalidates the exe file. Also the text file is so small it is a waste to zip it.
7
1493
by: darrel | last post by:
I'm creating a file upload tool, and want to allow only DOC, XLS, PDF, RTF or TXT files. I am using this to check: if (contentType = "application/msword") _ or (contentType = "application/rtf") _ or (contentType = "application/ms-excel") _ or (contentType = "application/pdf") _ or (contentType = "application/txt") then However, I'm not sure if that's the proper way...namly the 'msword' vs.
3
1579
by: ad | last post by:
I create a MemoryStream form a dataset: MemoryStream sm= new MemoryStream(); dsHealth.WriteXml(sm); I use Response.Write() to send this XML MemoryStream as file to client. What is the ContentType of Response I must set?
3
13943
by: letuce dance | last post by:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/plain"; Response.Write("help"); }
9
1355
by: CindyH | last post by:
Hi Trying to get this code to work for http xml post. I need the post to be xml (doc.outerxml) sent in single key name as stream. The following is the post code and code for receiving the request. When it hits the "myresponse = myrequest.GetResponse()" in the post code - I'm getting following error: "The remote server returned an error: (500) Internal Server Error". I don't know if I have something wrong with the post or receiving it on...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.