-
Notifications
You must be signed in to change notification settings - Fork 42
/
Global.asax.cs
98 lines (83 loc) · 3.25 KB
/
Global.asax.cs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using System.Web.Helpers;
using Newtonsoft.Json.Linq;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Services;
namespace SitefinityWebApp
{
public class Global : System.Web.HttpApplication
{
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("X-Frame-Options", "SAMEORIGIN");
}
protected void Application_Start()
{
AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
}
private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
{
EventHub.Subscribe<RequestEndEvent>(this.RequestEnd);
Task.Run(() =>
{
SystemManager.RunWithElevatedPrivilege(x =>
{
var notificationConfigPath = SystemManager.CurrentHttpContext.Server.MapPath(NotificationConfigLocation);
var jsonString = File.ReadAllText(notificationConfigPath);
var jObject = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString) as JObject;
if (jObject["StartDate"] == null)
{
jObject["StartDate"] = DateTime.UtcNow;
var updatedJsonString = jObject.ToString();
File.WriteAllText(notificationConfigPath, updatedJsonString);
}
});
});
}
private void RequestEnd(RequestEndEvent @event)
{
var response = SystemManager.CurrentHttpContext?.Response;
if (null == response || response.HeadersWritten)
return;
if (response.StatusCode != (int)HttpStatusCode.OK)
return;
var contextItems = SystemManager.CurrentHttpContext.Items;
if (bool.Parse(contextItems[SystemManager.IsBackendRequestKey].ToString()))
return;
if (response.Headers["Content-Type"] == null || !response.Headers["Content-Type"].StartsWith("text/html"))
return;
if (contextItems["sf_request_event_operation_Key"].ToString().Contains("/RestApi/Sitefinity/inlineediting") ||
contextItems["sf_request_event_operation_Key"].ToString().Contains("/Res/Telerik.Sitefinity.Web.UI.PublicControls.InlineEditing"))
return;
response.Write(watermarkHtml);
}
private readonly string NotificationConfigLocation = "~/Sitefinity/Notifications/notifications.json";
private readonly string watermarkHtml =
@"<style>
.sfWatermark {
font-family: 'Open Sans Regular';
font-size: 16px;
color: #000000;
text-align: center;
border: #FFD000;
background-color: #FFD000;
height: 45px;
line-height: 45px;
position: fixed;
top: 0px;
width: 100%;
}
header {
margin-top:45px;
}
</style>
<div class='sfWatermark'>
This is a demo site. All content and functionalities are for demo purposes only. Do not trust your personal data.
</div>";
}
}