If I were to respond to an http request with a plain text in PHP, I would do something like:
<?php
header('Content-Type: text/plain');
echo "This is plain text";
?>
How would I do the equivalent in ASP.NET?
If I were to respond to an http request with a plain text in PHP, I would do something like:
<?php
header('Content-Type: text/plain');
echo "This is plain text";
?>
How would I do the equivalent in ASP.NET?
Example in C# (for VB.NET just remove the end
;
):You may want to call
Response.Clear
beforehand in order to ensure there are no headers or content in the buffer already.You should use Response property of Page class:
If you only want to return plain text like that I would use an ashx file (Generic Handler in VS). Then just add the text you want to return in the ProcessRequest method.
This removes the added overhead of a normal aspx page.