Click here to Skip to main content
15,886,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Following is the simple server i have created.It just printing the "Welcome to message only.I would like to display a particular aspx page on it.What changes i need to apply for that in the below coding.

Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.IO;
using System.Diagnostics;

namespace WebServer
{
    class servernew
    {
        static void Main(string[] args)
        {
            HttpListener listner = null;
            try
            {
                listner= new HttpListener();
                listner.Prefixes.Add("http://localhost:1300/");
                listner.Start();
                while(true)
                {
                 Console.WriteLine("Waiting....");
                    HttpListenerContext context =listner.GetContext();
                    string msg = "Welcome to the server"; 
                    context.Response.ContentLength64=Encoding.UTF8.GetByteCount(msg);
                    context.Response.StatusCode=(int)HttpStatusCode.OK;
                    using(Stream stream=context.Response.OutputStream)
                    {
                        using(StreamWriter writer =new StreamWriter(stream))
                        {
                            writer.Write(msg);
                            
                        }
                    }
                    Console.WriteLine("Message Sent.....");
                }
            }
            catch(WebException e)
            {
                Console.WriteLine(e.Status);
            }
        }
    }
}
Posted
Comments
Pravin Patil, Mumbai 12-Oct-11 2:14am    
What do you mean by "display a particular aspx page on it"?
sreenathpktr 12-Oct-11 2:16am    
I mean,consider that i have created a aspx pge.Now when i run the server the aspx page need to be displayed on it instead of the message "Welcome to the server".

1 solution

Firstly you need to convert this from a console application to a Windows Forms application. Lots of samples can be found here[^] to help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900