Skip to content

Class HttpContextExtension ​

Namespace: Tool.Web
Assembly: Tool.Net.dll

对进行升级

csharp
public static class HttpContextExtension

Inheritance ​

object ← HttpContextExtension

Inherited Members ​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods ​

ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)

Remarks ​

代码由逆血提供支持

Properties ​

Accessor ​

获取全局HttpContext对象

csharp
public static IHttpContextAccessor Accessor { get; }

Property Value ​

IHttpContextAccessor

Current ​

获取当前http请求的HttpContext对象,带异常提示。

csharp
public static HttpContext Current { get; }

Property Value ​

HttpContext

CurrentPath ​

当前路径

csharp
public static string CurrentPath { get; }

Property Value ​

string

CurrentSchemeHost ​

获取有关当前请求的 域名部分 的信息。

csharp
public static string CurrentSchemeHost { get; }

Property Value ​

string

CurrentUrl ​

获取有关当前请求的 URL 的信息。

csharp
public static string CurrentUrl { get; }

Property Value ​

string

Methods ​

AddHttpException(HttpContext, int, string, params object[]) ​

设置错误,并指定错误号

csharp
public static Exception AddHttpException(this HttpContext context, int StatusCode, string format, params object[] args)

Parameters ​

context HttpContext

StatusCode int

format string

args object[]

Returns ​

Exception

AddHttpException(HttpContext, int, string, Exception, params object[]) ​

设置错误,并指定错误号

csharp
public static Exception AddHttpException(this HttpContext context, int StatusCode, string format, Exception error, params object[] args)

Parameters ​

context HttpContext

StatusCode int

format string

error Exception

args object[]

Returns ​

Exception

GetSchemeHost(HttpContext) ​

获取当前请求地址的 主要信息(支持代理模式信息获取)

csharp
public static (string scheme, string host) GetSchemeHost(this HttpContext context)

Parameters ​

context HttpContext

HttpContext

Returns ​

(string scheme, string host)

返回连接协议和原始主机请求地址

GetService<T>(HttpContext) ​

获取服务(在 System.IServiceProvider 从中检索服务对象。)

csharp
public static T GetService<T>(this HttpContext context)

Parameters ​

context HttpContext

HttpContext

Returns ​

T

类型为 T 或 null 的服务对象(如果没有此类服务)。

Type Parameters ​

T

要获取的服务对象的类型。

GetUserIp(HttpContext) ​

获取客户端请求的IP地址(支持代理模式信息获取)

有验证IP是否合法合规

csharp
public static string GetUserIp(this HttpContext context)

Parameters ​

context HttpContext

HttpContext

Returns ​

string

返回IP地址

GetUserIps(HttpContext) ​

获取客户端请求的IP地址(支持代理模式信息获取)

有验证IP是否合法合规

csharp
public static string GetUserIps(this HttpContext context)

Parameters ​

context HttpContext

HttpContext

Returns ​

string

返回IP地址或多个地址', '隔开

StreamMove(Stream, Stream, int) ​

将文件流分流写入

csharp
public static Task StreamMove(Stream ReadStream, Stream WriteStream, int minlen)

Parameters ​

ReadStream Stream

原文件流

WriteStream Stream

更新文件流

minlen int

最小资源大小

Returns ​

Task

基于Apache-2.0协议开源