Woopsa.HTTPResponse.WriteError C# (CSharp) Метод

WriteError() публичный Метод

Sends a nicely-formatted error with specified HTTP Error Code and Error Message to the client. This response is not buffered and thus calling this method will immediately send the response to the client.
public WriteError ( HTTPStatusCode errorCode, string errorMessage ) : void
errorCode HTTPStatusCode The HTTP Status Code to send
errorMessage string The Error Message to send. For example "Not Found" or "Not Supported"
Результат void
        public void WriteError(HTTPStatusCode errorCode, string errorMessage)
        {
            SendError((int)errorCode, errorMessage);
        }

Same methods

HTTPResponse::WriteError ( HTTPStatusCode errorCode, string errorMessage, string errorContent, string mimeType ) : void

Usage Example

Пример #1
0
        internal void HandleRequest(HTTPRequest request, HTTPResponse response, Stream stream)
        {
            try
            {
                bool        matchFound = false;
                RouteMapper mapper     = null;
                int         i          = 0;

                for (;;)
                {
                    lock (_routes)
                    {
                        if (i < _routes.Count)
                        {
                            mapper = _routes[i++];
                        }
                        else
                        {
                            break;
                        }
                    }
                    string regex = "^" + mapper.Route;
                    if (!mapper.AcceptSubroutes)
                    {
                        regex += "$";
                    }
                    if (Regex.IsMatch(request.BaseURL, regex))
                    {
                        if ((mapper.Methods & request.Method) != 0)
                        {
                            if (mapper.AcceptSubroutes)
                            {
                                int pos = request.BaseURL.IndexOf(mapper.Route);
                                request.Subroute = request.BaseURL.Substring(0, pos) + request.BaseURL.Substring(pos + mapper.Route.Length);
                            }
                            matchFound = true;
                            break;
                        }
                    }
                }

                if (!matchFound)
                {
                    response.WriteError(HTTPStatusCode.NotFound, "Not Found");
                    response.Respond(stream);
                    OnError(RoutingErrorType.NO_MATCHES, "No route found for request", request);
                }
                else
                {
                    mapper.HandleRequest(request, response);
                    response.Respond(stream);
                }
            }
            catch (Exception e)
            {
                response.WriteError(HTTPStatusCode.InternalServerError, String.Format("Internal Server Error {0}", e.Message));
                response.Respond(stream);
                OnError(RoutingErrorType.INTERNAL, "A RouteHandler threw an exception.", request);
            }
        }
All Usage Examples Of Woopsa.HTTPResponse::WriteError