SocketTools .NET Edition

HttpServer.SendError Method (Int32, String)

Send an error result code and message to the client in response to a command.

[Visual Basic]
Overloads Public Function SendError( _
   ByVal resultCode As Integer, _
   ByVal message As String _
) As Boolean
[C#]
public bool SendError(
   int resultCode,
   string message
);

Parameters

resultCode
An integer value that specifies the error code that should be sent to the client. This value should correspond to the error result codes defined for HTTP in RFC 2616, which are three-digit values in the range of 400 through 599. The method will fail if an invalid error code is specified.
message
An string value that specifies a message to be sent to the client. If this parameter is an empty string, a default message associated with the result code will be used.

Return Value

A boolean value which specifies if the error response was sent to the client. A return value of true specifies that the operation was successful. If an error occurs, the method returns false and the application should check the value of the LastError property to determine the cause of the failure.

Remarks

The SendError method sends a response to the client indicating that an error has occurred, providing a numeric error code and HTML formatted text which may be displayed to the user. The Message parameter should provide a brief description of the error that will be included in the output sent to the client. Note that the message should not contain any special formatting control characters or HTML markup.

This method provides a simplified interface for sending an error response to the client. In some cases, a browser may choose to display its own error message to the user in place of the generic HTML document generated by this method. If you want your application to send a customized HTML document for a specific type of error, you should use the SendResponse method.

If you wish to redirect the client to use an alternate URL to access the requested resource, it is recommended that you use the RedirectRequest method rather than sending an error response.

This version of the method uses the active client session and should only be called from within a server event handler. To specify a client session outside of an event handler, use the version of this method that accepts a client ID parameter.

See Also

HttpServer Class | SocketTools Namespace | HttpServer.SendError Overload List