RemObjects.InternetPack.Http.HttpServerResponse.SendError C# (CSharp) Method

SendError() public method

public SendError ( HttpStatusCode responseCode, Exception ex ) : void
responseCode HttpStatusCode
ex System.Exception
return void
		public void SendError(HttpStatusCode responseCode, Exception ex)
		{
			this.HttpCode = responseCode;

#if FULLFRAMEWORK
			String lMessageHtml = String.Format("<h1>Error {0} {1}</h1><p>{2}: {3}</p><p>{4}</p><hr /><p>{3}</p>",
													responseCode, ex.GetType().Name, ex.GetType().FullName, ex.Message, ex.StackTrace);
#else
            String lMessageHtml = String.Format("<h1>Error {0} {1}</h1><p>{2}: {3}</p><p>{4}</p><hr />",
                responseCode, ex.GetType().Name, ex.GetType().FullName, ex.Message, DEFAULT_SERVER_NAME);
#endif
			this.ContentBytes = Encoding.ASCII.GetBytes(lMessageHtml);
			this.Header.ContentType = "text/html";
		}

Same methods

HttpServerResponse::SendError ( HttpStatusCode responseCode, String message ) : void
HttpServerResponse::SendError ( Int32 responseCode, Exception ex ) : void
HttpServerResponse::SendError ( Int32 responseCode, String message ) : void

Usage Example

Example #1
0
        protected override void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
        {
            base.HandleHttpRequest(connection, request, response);

            if (response.ContentSource == ContentSource.ContentNone)
            {
                if (request.Header.RequestType == "GET")
                {
                    String lPath = RootPath + request.Header.RequestPath.Replace('/', Path.DirectorySeparatorChar);
                    if (lPath.IndexOf("..") == -1)
                    {
                        if (File.Exists(lPath))
                        {
                            response.Header.ContentType = "text/html";
                            response.ContentStream      = new FileStream(lPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                            response.CloseStream        = true; /* Response will close stream once it's been sent */
                        }
                        else
                        {
                            response.SendError(HttpStatusCode.NotFound, String.Format("File '{0}' not found.", lPath));
                        }
                    }
                    else
                    {
                        response.SendError(HttpStatusCode.Forbidden, String.Format("Bad Request: Path '{0}' contains '..' which is invalid.", lPath));
                    }
                }
                else
                {
                    response.SendError(HttpStatusCode.BadRequest, String.Format("Request Type '{0}' not supported.", request.Header.RequestType));
                }
            }
        }
All Usage Examples Of RemObjects.InternetPack.Http.HttpServerResponse::SendError