|
@@ -19,7 +19,7 @@ namespace IES.ExamServer
|
|
|
/// <typeparam name="TAttribute"></typeparam>
|
|
|
/// <param name="httpContext"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static TAttribute GetMetadata<TAttribute>(this HttpContext httpContext)
|
|
|
+ public static TAttribute? GetMetadata<TAttribute>(this HttpContext httpContext)
|
|
|
where TAttribute : class
|
|
|
{
|
|
|
return httpContext.GetEndpoint()?.Metadata?.GetMetadata<TAttribute>();
|
|
@@ -29,7 +29,7 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="httpContext"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static ControllerActionDescriptor GetControllerActionDescriptor(this HttpContext httpContext)
|
|
|
+ public static ControllerActionDescriptor? GetControllerActionDescriptor(this HttpContext httpContext)
|
|
|
{
|
|
|
return httpContext.GetEndpoint()?.Metadata?.FirstOrDefault(u => u is ControllerActionDescriptor) as ControllerActionDescriptor;
|
|
|
}
|
|
@@ -38,7 +38,7 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="context"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static string GetLocalIpAddressToIPv4(this HttpContext context)
|
|
|
+ public static string? GetLocalIpAddressToIPv4(this HttpContext context)
|
|
|
{
|
|
|
return context.Connection.LocalIpAddress?.MapToIPv4()?.ToString();
|
|
|
}
|
|
@@ -48,7 +48,7 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="context"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static string GetLocalIpAddressToIPv6(this HttpContext context)
|
|
|
+ public static string? GetLocalIpAddressToIPv6(this HttpContext context)
|
|
|
{
|
|
|
return context.Connection.LocalIpAddress?.MapToIPv6()?.ToString();
|
|
|
}
|
|
@@ -58,7 +58,7 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="context"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static string GetRemoteIpAddressToIPv4(this HttpContext context)
|
|
|
+ public static string? GetRemoteIpAddressToIPv4(this HttpContext context)
|
|
|
{
|
|
|
return context.Connection.RemoteIpAddress?.MapToIPv4()?.ToString();
|
|
|
}
|
|
@@ -68,7 +68,7 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="context"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static string GetRemoteIpAddressToIPv6(this HttpContext context)
|
|
|
+ public static string? GetRemoteIpAddressToIPv6(this HttpContext context)
|
|
|
{
|
|
|
return context.Connection.RemoteIpAddress?.MapToIPv6()?.ToString();
|
|
|
}
|
|
@@ -107,7 +107,7 @@ namespace IES.ExamServer
|
|
|
/// <param name="httpContext"></param>
|
|
|
/// <remarks>需先在 Startup 的 Configure 中注册 app.EnableBuffering()</remarks>
|
|
|
/// <returns></returns>
|
|
|
- public static async Task<string> ReadBodyContentAsync(this HttpContext httpContext)
|
|
|
+ public static async Task<string?> ReadBodyContentAsync(this HttpContext httpContext)
|
|
|
{
|
|
|
if (httpContext == null) return default;
|
|
|
return await httpContext.Request.ReadBodyContentAsync();
|
|
@@ -174,7 +174,7 @@ namespace IES.ExamServer
|
|
|
/// <summary>
|
|
|
/// 取得遠端呼叫的IP
|
|
|
/// </summary>
|
|
|
- public static string GetRemoteIP(this HttpContext httpContext)
|
|
|
+ public static string? GetRemoteIP(this HttpContext httpContext)
|
|
|
{
|
|
|
return httpContext?.Connection?.RemoteIpAddress?.ToString();
|
|
|
}
|
|
@@ -184,7 +184,7 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="key">Key Name</param>
|
|
|
/// <returns></returns>
|
|
|
- public static string GetXAuth(this HttpContext httpContext, string key = null)
|
|
|
+ public static string? GetXAuth(this HttpContext httpContext, string? key = null)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -203,7 +203,7 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="key">Key Name</param>
|
|
|
/// <returns></returns>
|
|
|
- public static string GetAuthorization(this HttpContext httpContext)
|
|
|
+ public static string? GetAuthorization(this HttpContext httpContext)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -222,9 +222,9 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="key">Key Name</param>
|
|
|
/// <returns></returns>
|
|
|
- public static (string id, string school) GetApiTokenInfo(this HttpContext httpContext, string key = null)
|
|
|
+ public static (string? id, string? school) GetApiTokenInfo(this HttpContext httpContext, string? key = null)
|
|
|
{
|
|
|
- object id = null, school = null;
|
|
|
+ object? id = null, school = null;
|
|
|
httpContext?.Items.TryGetValue("ID", out id);
|
|
|
httpContext?.Items.TryGetValue("School", out school);
|
|
|
return (id?.ToString(), school?.ToString());
|
|
@@ -234,9 +234,9 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="key">Key Name</param>
|
|
|
/// <returns></returns>
|
|
|
- public static (string id, string name, string picture, string school) GetAuthTokenInfo(this HttpContext httpContext, string key = null)
|
|
|
+ public static (string? id, string? name, string? picture, string? school) GetAuthTokenInfo(this HttpContext httpContext, string? key = null)
|
|
|
{
|
|
|
- object id = null, name = null, picture = null, school = null;
|
|
|
+ object? id = null, name = null, picture = null, school = null;
|
|
|
httpContext?.Items.TryGetValue("ID", out id);
|
|
|
httpContext?.Items.TryGetValue("Name", out name);
|
|
|
httpContext?.Items.TryGetValue("Picture", out picture);
|
|
@@ -249,9 +249,9 @@ namespace IES.ExamServer
|
|
|
/// </summary>
|
|
|
/// <param name="key">Key Name</param>
|
|
|
/// <returns></returns>
|
|
|
- public static (string id, string name, string picture, string school, string area, string keyData) GetAuthTokenKey(this HttpContext httpContext, string key = null)
|
|
|
+ public static (string? id, string? name, string? picture, string? school, string? area, string? keyData) GetAuthTokenKey(this HttpContext httpContext, string key = null)
|
|
|
{
|
|
|
- object id = null, name = null, picture = null, school = null, area = null, keyData = null;
|
|
|
+ object? id = null, name = null, picture = null, school = null, area = null, keyData = null;
|
|
|
httpContext?.Items.TryGetValue("ID", out id);
|
|
|
httpContext?.Items.TryGetValue("Name", out name);
|
|
|
httpContext?.Items.TryGetValue("Picture", out picture);
|
|
@@ -266,7 +266,7 @@ namespace IES.ExamServer
|
|
|
/// <summary>
|
|
|
/// 取得User-Agent值
|
|
|
/// </summary>
|
|
|
- public static string GetUserAgent(this HttpContext httpContext)
|
|
|
+ public static string? GetUserAgent(this HttpContext httpContext)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -281,7 +281,7 @@ namespace IES.ExamServer
|
|
|
/// <summary>
|
|
|
/// 取得Scheme值
|
|
|
/// </summary>
|
|
|
- public static string GetScheme(this HttpContext httpContext)
|
|
|
+ public static string? GetScheme(this HttpContext httpContext)
|
|
|
{
|
|
|
return httpContext?.Request?.Scheme;
|
|
|
}
|
|
@@ -289,7 +289,7 @@ namespace IES.ExamServer
|
|
|
/// <summary>
|
|
|
/// 取得HostName值
|
|
|
/// </summary>
|
|
|
- public static string GetHostName(this HttpContext httpContext)
|
|
|
+ public static string? GetHostName(this HttpContext httpContext)
|
|
|
{
|
|
|
return httpContext?.Request?.Host.ToString();
|
|
|
}
|