DataWeb
Search Results for

    Show / Hide Table of Contents

    Class HttpService

    An implementation of the IHttpService interface for working with HTTP-related tasks.

    Inheritance
    object
    HttpService
    Implements
    IHttpService
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: DataWeb.Http
    Assembly: DataWeb.Core.dll
    Syntax
    public class HttpService : IHttpService

    Constructors

    HttpService(IHttpContextAccessor, LinkGenerator)

    An implementation of the IHttpService interface for working with HTTP-related tasks.

    Declaration
    public HttpService(IHttpContextAccessor httpContextAccessor, LinkGenerator linkGenerator)
    Parameters
    Type Name Description
    IHttpContextAccessor httpContextAccessor

    The HTTP context accessor used to retrieve the current HttpContext.

    LinkGenerator linkGenerator

    The link generator used to build route URLs.

    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
    public 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
    public 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
    public 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
    public 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
    public 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
    public 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
    public 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
    public 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.

    Implements

    IHttpService
    In this article
    Back to top Generated by DocFX