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. |
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. |
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 |
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 |
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. |
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 |
| bool | isAbsoluteUrl |
|
Returns
| Type | Description |
|---|---|
| string | The generated URL, or |
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 |
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 |