forked from BlogEngine/BlogEngine.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobal.asax
More file actions
48 lines (44 loc) · 1.63 KB
/
Copy pathGlobal.asax
File metadata and controls
48 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<%@ Application Language="C#" %>
<%@ Import Namespace="BlogEngine.NET.App_Start" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script RunAt="server">
void Application_BeginRequest(object sender, EventArgs e)
{
var app = (HttpApplication)sender;
BlogEngineConfig.Initialize(app.Context);
}
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
BlogEngineConfig.SetCulture(sender, e);
}
protected void Application_EndRequest(object sender, EventArgs e)
{
// Properly set SameSite attribute on cookies for .NET Framework 4.8
var httpContext = HttpContext.Current;
if (httpContext != null && httpContext.Response != null)
{
var cookies = httpContext.Response.Headers.GetValues("Set-Cookie");
if (cookies != null)
{
var modifiedCookies = new List<string>();
foreach (var cookie in cookies)
{
// Only add SameSite if not already present
if (!cookie.Contains("SameSite="))
{
modifiedCookies.Add(cookie + "; SameSite=Lax");
}
else
{
modifiedCookies.Add(cookie);
}
}
httpContext.Response.Headers.Remove("Set-Cookie");
foreach (var modifiedCookie in modifiedCookies)
{
httpContext.Response.Headers.Add("Set-Cookie", modifiedCookie);
}
}
}
}
</script>