0

i have create localhost using following code in c#

static HttpListener _httpListener = new HttpListener();



    

    [STAThread]
    static void Main()
    {
        Console.WriteLine("Starting server...");
        _httpListener.Prefixes.Add("http://localhost:5000/"); // add prefix "http://localhost:5000/"
        _httpListener.Start(); // start server (Run application as Administrator!)
        Console.WriteLine("Server started.");
        Thread _responseThread = new Thread(ResponseThread);
        _responseThread.Start(); // start the response thread
        
    }

my question is that i have a c# wesite in a folder. and i want to run this website using created localhost:5000. can any one suggest me proper solution.

Thanks Nirmal

static void ResponseThread()
        {
            while (true)
            {
                HttpListenerContext context = _httpListener.GetContext(); 
                                                                          byte[] _responseArray = Encoding.UTF8.GetBytes( "<html><head><title>Localhost server -- port 5000</title></head>" +
                                                                          <body>Welcome to  <strong>Localhost server</strong> -- <em>port 5000!</em></body></html>"); 

                byte[] _responseArray = Encoding.UTF8.GetBytes(str); // get the bytes to response

                context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length); // write bytes to the output stream
                context.Response.KeepAlive = false; // set the KeepAlive bool to false
                context.Response.Close(); // close the connection
                Console.WriteLine("Respone given to a request.");
            }
        }

message is displaying in localhost:500 but i want to run my c# website using this code.

jdweng
  • 33,250
  • 2
  • 15
  • 20
nirmal
  • 1

0 Answers0