parent
0e5b370ee8
commit
93bc1cd5af
|
@ -16,6 +16,11 @@ namespace Oqtane.UI
|
|||
_jsRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
public async Task SetCookie(string name, string value, int days)
|
||||
{
|
||||
await SetCookie(name, value, days, true, "Lax");
|
||||
}
|
||||
|
||||
public Task SetCookie(string name, string value, int days, bool secure, string sameSite)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -6,11 +6,11 @@ Oqtane.Interop = {
|
|||
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
var expires = "expires=" + d.toUTCString();
|
||||
var cookieString = name + "=" + value + ";" + expires + ";path=/";
|
||||
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
|
||||
cookieString += `; SameSite=${sameSite}`;
|
||||
}
|
||||
if (secure) {
|
||||
cookieString += "; Secure";
|
||||
cookieString += "; secure";
|
||||
}
|
||||
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
|
||||
cookieString += "; SameSite=" + sameSite;
|
||||
}
|
||||
document.cookie = cookieString;
|
||||
},
|
||||
|
|
|
@ -609,7 +609,7 @@
|
|||
Expires = DateTimeOffset.UtcNow.AddYears(1),
|
||||
SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax, // Set SameSite attribute
|
||||
Secure = true, // Ensure the cookie is only sent over HTTPS
|
||||
HttpOnly = true // Optional: Helps mitigate XSS attacks
|
||||
HttpOnly = false // cookie is updated using JS Interop
|
||||
};
|
||||
|
||||
Context.Response.Cookies.Append(
|
||||
|
|
|
@ -6,11 +6,11 @@ Oqtane.Interop = {
|
|||
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
var expires = "expires=" + d.toUTCString();
|
||||
var cookieString = name + "=" + value + ";" + expires + ";path=/";
|
||||
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
|
||||
cookieString += `; SameSite=${sameSite}`;
|
||||
}
|
||||
if (secure) {
|
||||
cookieString += "; Secure";
|
||||
cookieString += "; secure";
|
||||
}
|
||||
if (sameSite === "Lax" || sameSite === "Strict" || sameSite === "None") {
|
||||
cookieString += "; SameSite=" + sameSite;
|
||||
}
|
||||
document.cookie = cookieString;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user