DataWeb
Search Results for

    Show / Hide Table of Contents

    Interface IHttpService

    Defines methods for working with HTTP-related services, such as retrieving request and application URLs, working with route URLs, and encoding URLs.

    Namespace: DataWeb.Http
    Assembly: DataWeb.Core.dll
    Syntax
    public interface IHttpService

    Methods

    GetAppUrl()

    Gets the base application URL (scheme, host, and path base) from the current HTTP context. Any trailing slash is removed from the returned value.

    Declaration
    string GetAppUrl()
    Returns
    Type Description
    string

    The application base URL (e.g. https://example.com/app), or null if the HTTP context is not available.

    GetPathAndQuery()

    Gets the encoded path and query string of the current request.

    Declaration
    string GetPathAndQuery()
    Returns
    Type Description
    string

    The encoded path and query string (e.g. /path?q=1), or null if the HTTP context is not available.

    GetRemoteIpAddress()

    Gets the remote IP address of the client making the request.

    Declaration
    string GetRemoteIpAddress()
    Returns
    Type Description
    string

    The remote IP address as a string, or null if the HTTP context is not available or the address cannot be determined.

    Remarks

    This returns the direct connection IP. In environments behind a reverse proxy or load balancer, the value may reflect the proxy address rather than the real client IP.

    GetRequestMethod()

    Gets the HTTP method of the current request (e.g. GET, POST).

    Declaration
    string GetRequestMethod()
    Returns
    Type Description
    string

    The HTTP method of the current request, or null if the HTTP context is not available.

    GetRequestUrl()

    Gets the fully encoded URL of the current request.

    Declaration
    string GetRequestUrl()
    Returns
    Type Description
    string

    The encoded URL of the current request (e.g. https://example.com/path?q=1), or null if the HTTP context is not available.

    GetRouteUrl(string, object, bool)

    Gets the URL for a named route with optional parameters.

    Declaration
    string GetRouteUrl(string routeName, object parameters = null, bool isAbsoluteUrl = false)
    Parameters
    Type Name Description
    string routeName

    The name of the route to generate the URL for.

    object parameters

    An object containing route parameter values, or null for no parameters.

    bool isAbsoluteUrl

    true to return an absolute URL including scheme and host; false to return a relative path.

    Returns
    Type Description
    string

    The generated URL, or null if the route is not found. When isAbsoluteUrl is true, also returns null if the HTTP context is not available.

    GetUrlQueryParameter(string, string)

    Retrieves the value of a query parameter from a URL or relative path. The parameter name comparison is case-insensitive.

    Declaration
    string GetUrlQueryParameter(string url, string parameterName)
    Parameters
    Type Name Description
    string url

    The URL or relative path containing the query string.

    string parameterName

    The name of the query parameter to retrieve.

    Returns
    Type Description
    string

    The value of the query parameter, or null if the parameter is not found, the URL contains no query string, or either argument is null or whitespace.

    UrlEncode(string)

    Encodes a URL string using standard URL encoding rules.

    Declaration
    string UrlEncode(string url)
    Parameters
    Type Name Description
    string url

    The string to encode.

    Returns
    Type Description
    string

    The URL-encoded string, or null if url is null.

    In this article
    Back to top Generated by DocFX