Cassini.Connection.WriteEntireResponseFromString C# (CSharp) Method

WriteEntireResponseFromString() public method

public WriteEntireResponseFromString ( int statusCode, String extraHeaders, String body, bool keepAlive ) : void
statusCode int
extraHeaders String
body String
keepAlive bool
return void
        public void WriteEntireResponseFromString(int statusCode, String extraHeaders, String body, bool keepAlive)
        {
            try {
                int bodyLength = (body != null) ? Encoding.UTF8.GetByteCount(body) : 0;
                string headers = MakeResponseHeaders(statusCode, extraHeaders, bodyLength, keepAlive);

                _socket.Send(Encoding.UTF8.GetBytes(headers + body));
            }
            catch (SocketException) {
            }
            finally {
                if (!keepAlive) {
                    Close();
                }
            }
        }

Usage Example

Esempio n. 1
0
        bool ProcessDirectoryRequest()
        {
            String dirPathTranslated = _pathTranslated;

            if (_pathInfo.Length > 0)
            {
                // directory path can never have pathInfo
                dirPathTranslated = MapPath(_path);
            }

            if (!Directory.Exists(dirPathTranslated))
            {
                return(false);
            }

            // have to redirect /foo to /foo/ to allow relative links to work
            if (!_path.EndsWith("/", StringComparison.Ordinal))
            {
                string newPath  = _path + "/";
                string location = "Location: " + UrlEncodeRedirect(newPath) + "\r\n";
                string body     = "<html><head><title>Object moved</title></head><body>\r\n" +
                                  "<h2>Object moved to <a href='" + newPath + "'>here</a>.</h2>\r\n" +
                                  "</body></html>\r\n";

                _connection.WriteEntireResponseFromString(302, location, body, false);
                return(true);
            }

            // check for the default file
            foreach (string filename in defaultFileNames)
            {
                string defaultFilePath = dirPathTranslated + "\\" + filename;

                if (File.Exists(defaultFilePath))
                {
                    // pretend the request is for the default file path
                    _path          += filename;
                    _filePath       = _path;
                    _url            = (_queryString != null) ? (_path + "?" + _queryString) : _path;
                    _pathTranslated = defaultFilePath;
                    return(false); // go through normal processing
                }
            }

            return(false); // go through normal processing
        }
All Usage Examples Of Cassini.Connection::WriteEntireResponseFromString