How do I get my server (AWS EC2) to send the .html file as html in C #?

I have a server configured using an Amazon Web Service EC2 VM.

My server application written in C #.

Currently, my JavaScript game can send data to the server and receive JSON objects when requesting data for the high score bar. This all works great.

I decided to try to host my game from the server. For some reason, if you ask for the index.html file, what the clients browser interprets is raw text. As you can see here ( http://i.imgur.com/uE9zOaA.png ) it renders the index.html file as text and it just puts it in clients body under the "pre" tag.

I originally thought it was a security thing, but I can't find anything in the security of my EC2 instance that would prevent this from happening. Also, when I host it using localhost: 8080 through Visual Studio, I have the same thing that makes me think it's in my code.

It is also worth adding that I went through my regedit and made sure that all the .html stuff is of type text / html.

In C #, after determining what the user was trying to request (which I know works since it was fetching the correct html file), it calls the following method.

private static Response IndexRequest()
    {
        String file = "C:\\Game\\index.html";
        FileInfo fi = new FileInfo(file);
        FileStream fs = fi.OpenRead();
        BinaryReader reader = new BinaryReader(fs);
        Byte[] d = new Byte[fs.Length];
        reader.Read(d, 0, d.Length);
        fs.Close();

        return new Response("Play", "text/html", d);
    }

      

This method essentially reads the index.html file and changes it to an array of bytes to send, and then returns a Play object of type "text / html" that contains the array.

Whoever calls this method receives a Response object with this data. This Response object is then asked to call its post method, which looks like this.

public void Post(NetworkStream stream) {
        StreamWriter writer = new StreamWriter(stream);
        writer.WriteLine(String.Format("{0} {1}\r\nServer: {2}\r\nContent-Type: {3}\r\nAccept-Ranges: bytes\r\nContent-Length: {4}\r\n",
            HTTPServer.VERSION, status, HTTPServer.NAME, mime, data.Length));

        stream.Write(data, 0, data.Length);
    }

      

Where HTTPServer.VERSION == "HTTP / 1.1", HTTPServer.NAME = "HarbourGuide HTTP Server V0.1" and status / mime / data are the three things returned as parameters from the first method (in this case, the "Play" data , "text / html", index.html as a bbyte array.

As I said, this results in the client receiving the data as text. Changing mimes to "html" doesn't work.

Any help would be greatly appreciated. Thank.

+3


source to share





All Articles