コード例 #1
0
 /// <summary>
 /// this method converts the byte[] to ascii values.
 /// </summary>
 /// <param name="newHTTPResponse">the response struct to read the file</param>
 /// <param name="buffer">the buffer to read.</param>
 /// <returns></returns>
 public string convertToString(ResponseStruct newHTTPResponse, byte[] buffer)
 {
     int numberOfBytes = 0;
     string file = string.Empty;
     while ((numberOfBytes = this.newHTTPResponse.newFileStream.Read(buffer, 0, buffer.Length)) > 0)
     {
         file += Encoding.UTF8.GetString(buffer);
     }
     return file;
 }
コード例 #2
0
        /// <summary>
        /// This method searches for the file requested by the browser. if it does not exist than it will
        /// send an error page(file not found).
        /// </summary>
        /// <param name="RequestReference"> reference struct with all information about the new request</param>
        /// <param name="ResponseReference">reference struct with information to be send.</param>
        public override void OnResponse(ref RequestStruct RequestReference, ref ResponseStruct ResponseReference)
        {
            string path = this.Container  + RequestReference.url.Replace("/", "\\");
            if (Directory.Exists(path))
            {
                if(File.Exists(path + FileName))
                {
                    path += "\\"+ FileName;
                }
            }

            if (File.Exists(path))
            {

                ResponseReference.newFileStream = File.Open(path, FileMode.Open);

                RequestReference.headers["Content-type"] = "text";

            }
            else
            {

                ResponseReference.status = (int)ResponseState.NOT_FOUND;

                string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
                bodyStr += "<HTML><HEAD>\n";
                bodyStr += "<title>IIS Detailed Error - 404 - Not Found</title> \n";
                bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
                bodyStr += "</HEAD>\n";
                bodyStr += "<BODY>\n";
                bodyStr += "<fieldset><legend>Error Summary</legend>\n";
                bodyStr += "<h2>HTTP Error 404 - Not Found</h2>\n";
                bodyStr += "<h3>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</h3>\n";
                bodyStr += "</fieldset>\n ";
                bodyStr += "</BODY></HTML>\n";

                ResponseReference.DataInBody = Encoding.ASCII.GetBytes(bodyStr);

            }
        }
コード例 #3
0
        /// <summary>
        /// This function will send an 500 error if there is a problem with the script.
        /// </summary>
        /// <param name="ResponseReference">reference struct with information to be send.</param>
        public override void serverError(ref ResponseStruct ResponseReference)
        {
            ResponseReference.status = (int)ResponseState.SERVER_ERROR;
            string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
            bodyStr += "<HTML><HEAD>\n";
            bodyStr += "<title>Server Error 500 Invalid Script.</title> \n";
            bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
            bodyStr += "</HEAD>\n";
            bodyStr += "<BODY>\n";
            bodyStr += "<fieldset><legend>Error Summary</legend>\n";
            bodyStr += "<h2>Server Error 500 Invalid Script</h2>\n";
            bodyStr += "<h3>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</h3>\n";
            bodyStr += "</fieldset>\n ";
            bodyStr += "</BODY></HTML>\n";

            ResponseReference.DataInBody = Encoding.ASCII.GetBytes(bodyStr);
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: GeorgianCostea/Xanders-Work
 /// <summary>
 /// method to be overritten by the child class.
 /// </summary>
 /// <param name="ResponseReference"></param>
 public abstract void serverError(ref ResponseStruct ResponseReference);
コード例 #5
0
ファイル: Server.cs プロジェクト: GeorgianCostea/Xanders-Work
 /// <summary>
 /// method to be overriten by the child class
 /// </summary>
 /// <param name="RequestReference"></param>
 /// <param name="ResponseReference"></param>
 public abstract void OnResponse(ref RequestStruct RequestReference, ref ResponseStruct ResponseReference);