Class HttpService
An implementation of the IHttpService interface for working with HTTP-related tasks.
Implements
Inherited Members
Namespace: DataWeb.Http
Assembly: DataWeb.Core.dll
Syntax
public class HttpService : IHttpService
Remarks
Initializes a new instance of the HttpService class.
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. |
LinkGenerator | linkGenerator | The link generator. |
Remarks
Initializes a new instance of the HttpService class.
Methods
GetAppUrl()
Gets the application URL based on the current HTTP context.
Declaration
public string GetAppUrl()
Returns
Type | Description |
---|---|
string | The application URL, or |
Remarks
This method uses the IHttpContextAccessor to retrieve the current HTTP context.
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 of the current request, or |
Remarks
This method uses the IHttpContextAccessor to retrieve the current HTTP context.
GetRemoteIpAddress()
Gets the remote IP address of the client making the request.
Declaration
public string GetRemoteIpAddress()
Returns
Type | Description |
---|---|
string | The remote IP address of the client making the request, or |
Remarks
This method uses the IHttpContextAccessor to retrieve the current HTTP context.
GetRequestMethod()
Gets the HTTP method of the current request.
Declaration
public string GetRequestMethod()
Returns
Type | Description |
---|---|
string | The HTTP method of the current request, or |
Remarks
This method uses the IHttpContextAccessor to retrieve the current HTTP context.
GetRequestUrl()
Gets the encoded URL of the current request.
Declaration
public string GetRequestUrl()
Returns
Type | Description |
---|---|
string | The encoded URL of the current request, or |
Remarks
This method uses the IHttpContextAccessor to retrieve the current HTTP context.
GetRouteUrl(string, object, bool)
Gets the URL for a route with the specified name and parameters.
Declaration
public string GetRouteUrl(string routeName, object parameters, bool isAbsoluteUrl)
Parameters
Type | Name | Description |
---|---|---|
string | routeName | The name of the route to generate the URL for. |
object | parameters | An object that contains the parameters for the route. |
bool | isAbsoluteUrl |
|
Returns
Type | Description |
---|---|
string | The generated URL for the route, or |
Remarks
This method uses the IHttpContextAccessor and LinkGenerator to generate the URL for the route.
UrlEncode(string)
Encodes the specified URL string using URL encoding rules.
Declaration
public string UrlEncode(string url)
Parameters
Type | Name | Description |
---|---|---|
string | url | The URL string to encode. |
Returns
Type | Description |
---|---|
string | The encoded URL string. |
Remarks
This method uses the UrlEncode(string) method to encode the URL string.