Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2004, 11:45 AM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Content-type = text/html

Hi All,

I am trying to set a HTTP header to "text/html" and I am having no joy.

This is what I have so far... Am I far off? How can I do this?


using System;

class Hello
{
     static void Main()
     {
          Console.ContentType = "text/html";
          Console.WriteLine("Hello World");
     }
}

Thanks in advance.
 
Old December 4th, 2004, 01:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi tarran,

What exactly is the point of setting the ContentType of the console in a console application???

I think you're mixing COnsole Applications and Web applications...


What exactly are you trying to accomplish?

Imar
 
Old December 4th, 2004, 05:18 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Firstly, thank you for your reply.

I am trying to make a CGI application but I don't want to use ASP.NET - Just straight c#... I am rather new to C# and maybe there is a better way to do this however If I wanted to do the same thing in c++ i would do:

#include <iostream.h>

int main(){
    cout << "Content-type: text/plain" << endl << endl
    << "Hello World";
}

Am I going about this the wrong way? How should I be doing this remembering I don't want to use ASP.NET, only c#?

Thanks once again.
Tarran

 
Old December 5th, 2004, 08:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi again,

Well, a Console application won't cut it, as it will only run like a console application. I don't think you can tell IIS or any other Web server to redirect requests to the console.

What you probably need to create is your own custom HttpHandler that can run as an ISAPI extension . You can configure IIS applications to redirect requests to your HttpHandler, allowing you to bypass or enhance the ASP.NET functionality.
A while ago I created an HttpHandler to build a more powerful redirector that redirected Web sites to another server, while maintaining QueryString variables and logging the redirects. It was as easy as inheriting the right classes / implementing interfaces, and adding a few lines of code.

Here's the MSDN start page for HttpHandlers: http://msdn.microsoft.com/library/de...asp?frame=true

Another interesting article: http://www.15seconds.com/issue/020417.htm

Searching Google for HttpHandlers .NET will give you quite some interesting results.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Content-type: text/html\n\n - needed every time? crmpicco Perl 2 November 13th, 2006 11:09 AM
content="text/html; charset=iso-8859-1" crmpicco HTML Code Clinic 6 June 17th, 2005 05:09 AM
How To Type the text of html tag in TextBox 6cet6 ASP.NET 1.0 and 1.1 Basics 3 November 6th, 2003 05:30 AM
Retrive text from input type field of html file?? bikash Javascript 10 July 30th, 2003 04:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.