Add cookie support on IWebContext.
This commit is contained in:
@@ -36,6 +36,23 @@ public class AspnetCoreWebContext : IWebContext
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<string, string>? _requestCookies;
|
||||
|
||||
public Dictionary<string, string> RequestCookies
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_requestCookies == null)
|
||||
{
|
||||
_requestCookies = _context.Request.Cookies
|
||||
.ToDictionary(p => p.Key, p => p.Value);
|
||||
}
|
||||
|
||||
return _requestCookies;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, string?>? _requestQuery;
|
||||
|
||||
public Dictionary<string, string?> RequestQuery
|
||||
@@ -95,6 +112,20 @@ public class AspnetCoreWebContext : IWebContext
|
||||
_context.Response.Redirect(url);
|
||||
}
|
||||
|
||||
public void AddResponseCookie(string cookieName, string value, DateTime? expiration = null)
|
||||
{
|
||||
_context.Response.Cookies.Append(
|
||||
key: cookieName,
|
||||
value: value,
|
||||
options: new CookieOptions {Expires = expiration,}
|
||||
);
|
||||
}
|
||||
|
||||
public void DelResponseCookie(string cookieName)
|
||||
{
|
||||
_context.Response.Cookies.Delete(cookieName);
|
||||
}
|
||||
|
||||
public bool ResponseHasStarted => _context.Response.HasStarted;
|
||||
|
||||
public int ResponseStatusCode
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VAR.WebFormsCore.Code;
|
||||
@@ -6,14 +7,17 @@ public interface IWebContext
|
||||
{
|
||||
string RequestPath { get; }
|
||||
string RequestMethod { get; }
|
||||
Dictionary<string, string?> RequestForm { get; }
|
||||
Dictionary<string, string?> RequestQuery { get; }
|
||||
Dictionary<string, string?> RequestHeader { get; }
|
||||
Dictionary<string, string> RequestCookies { get; }
|
||||
Dictionary<string, string?> RequestQuery { get; }
|
||||
Dictionary<string, string?> RequestForm { get; }
|
||||
|
||||
void ResponseWrite(string text);
|
||||
void ResponseWriteBin(byte[] content);
|
||||
void ResponseFlush();
|
||||
void ResponseRedirect(string url);
|
||||
void AddResponseCookie(string cookieName, string value, DateTime? expiration = null);
|
||||
void DelResponseCookie(string cookieName);
|
||||
|
||||
bool ResponseHasStarted { get; }
|
||||
int ResponseStatusCode { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user