forked from dnnsoftware/Dnn.Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDotNetNukeHttpApplication.cs
More file actions
251 lines (219 loc) · 11.9 KB
/
DotNetNukeHttpApplication.cs
File metadata and controls
251 lines (219 loc) · 11.9 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Web.Common.Internal
{
using System;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Security;
using DotNetNuke.Abstractions.Application;
using DotNetNuke.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.ComponentModel;
using DotNetNuke.Data;
using DotNetNuke.Framework;
using DotNetNuke.HttpModules.DependencyInjection;
using DotNetNuke.Instrumentation;
using DotNetNuke.Modules.HTMLEditorProvider;
using DotNetNuke.Modules.NavigationProvider;
using DotNetNuke.Security.Cookies;
using DotNetNuke.Security.Membership;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Profile;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Cache;
using DotNetNuke.Services.ClientCapability;
using DotNetNuke.Services.Cryptography;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Installer.Blocker;
using DotNetNuke.Services.Log.EventLog;
using DotNetNuke.Services.Mail;
using DotNetNuke.Services.ModuleCache;
using DotNetNuke.Services.OutputCache;
using DotNetNuke.Services.Scheduling;
using DotNetNuke.Services.Search.Internals;
using DotNetNuke.Services.Sitemap;
using DotNetNuke.Services.Tokens;
using DotNetNuke.Services.Url.FriendlyUrl;
/// <summary>DotNetNuke Http Application. It will handle Start, End, BeginRequest, Error event for whole application.</summary>
public class DotNetNukeHttpApplication : HttpApplication
{
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(DotNetNukeHttpApplication));
private static readonly string[] Endings = [".css", ".gif", ".jpeg", ".jpg", ".js", ".png", "scriptresource.axd", "webresource.axd",];
static DotNetNukeHttpApplication()
{
var dependencyProvider = new LazyServiceProvider();
Globals.DependencyProvider = dependencyProvider;
ComponentFactory.Container = new ContainerWithServiceProviderFallback(new SimpleContainer(Globals.DependencyProvider), Globals.DependencyProvider);
ComponentFactory.InstallComponents(new ProviderInstaller("databaseConnection", typeof(DatabaseConnectionProvider), typeof(SqlDatabaseConnectionProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("data", typeof(DataProvider), typeof(SqlDataProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("caching", typeof(CachingProvider), typeof(FBCachingProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("logging", typeof(LoggingProvider), typeof(DBLoggingProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("scheduling", typeof(SchedulingProvider), typeof(DNNScheduler)));
ComponentFactory.InstallComponents(new ProviderInstaller("members", typeof(MembershipProvider), typeof(AspNetMembershipProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("roles", typeof(RoleProvider), typeof(DNNRoleProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("profiles", typeof(ProfileProvider), typeof(DNNProfileProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("permissions", typeof(PermissionProvider), typeof(CorePermissionProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("outputCaching", typeof(OutputCachingProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("moduleCaching", typeof(ModuleCachingProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("sitemap", typeof(SitemapProvider), typeof(CoreSitemapProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("friendlyUrl", typeof(FriendlyUrlProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("folder", typeof(FolderProvider)));
RegisterIfNotAlreadyRegistered<FolderProvider, StandardFolderProvider>("StandardFolderProvider");
RegisterIfNotAlreadyRegistered<FolderProvider, SecureFolderProvider>("SecureFolderProvider");
RegisterIfNotAlreadyRegistered<FolderProvider, DatabaseFolderProvider>("DatabaseFolderProvider");
ComponentFactory.InstallComponents(new ProviderInstaller("htmlEditor", typeof(HtmlEditorProvider), ComponentLifeStyleType.Transient));
ComponentFactory.InstallComponents(new ProviderInstaller("navigationControl", typeof(NavigationProvider), ComponentLifeStyleType.Transient));
ComponentFactory.InstallComponents(new ProviderInstaller("clientcapability", typeof(ClientCapabilityProvider)));
#pragma warning disable CS0618 // Type or member is obsolete
ComponentFactory.InstallComponents(new ProviderInstaller("cryptography", typeof(CryptographyProvider), typeof(FipsCompilanceCryptographyProvider)));
#pragma warning restore CS0618 // Type or member is obsolete
ComponentFactory.InstallComponents(new ProviderInstaller("tokens", typeof(TokenProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("mail", typeof(MailProvider)));
dependencyProvider.SetProvider(DependencyInjectionInitialize.BuildServiceProvider());
ServiceRequestScopeModule.SetServiceProvider(Globals.DependencyProvider);
HttpRuntime.WebObjectActivator = new WebFormsServiceProvider();
}
private static void RegisterIfNotAlreadyRegistered<TConcrete>()
where TConcrete : class, new()
{
RegisterIfNotAlreadyRegistered<TConcrete, TConcrete>(string.Empty);
}
private static void RegisterIfNotAlreadyRegistered<TAbstract, TConcrete>(string name)
where TAbstract : class
where TConcrete : class, new()
{
var provider = ComponentFactory.GetComponent<TAbstract>();
if (provider == null)
{
if (string.IsNullOrEmpty(name))
{
ComponentFactory.RegisterComponentInstance<TAbstract>(new TConcrete());
}
else
{
ComponentFactory.RegisterComponentInstance<TAbstract>(name, new TConcrete());
}
}
}
private static bool IsInstallOrUpgradeRequest(HttpRequest request)
{
var url = request.Url.LocalPath;
return url.EndsWith("webresource.axd", StringComparison.OrdinalIgnoreCase)
|| url.EndsWith("scriptresource.axd", StringComparison.OrdinalIgnoreCase)
|| url.EndsWith("captcha.aspx", StringComparison.OrdinalIgnoreCase)
|| url.Contains("upgradewizard.aspx", StringComparison.OrdinalIgnoreCase)
|| url.Contains("installwizard.aspx", StringComparison.OrdinalIgnoreCase)
|| url.EndsWith("install.aspx", StringComparison.OrdinalIgnoreCase);
}
private static bool IsInstallInProgress(HttpApplication app)
{
return InstallBlocker.Instance.IsInstallInProgress();
}
private void Application_End(object sender, EventArgs eventArgs)
{
Logger.Info("Application Ending");
try
{
Initialize.LogEnd();
}
catch (Exception e)
{
Logger.Error(e);
}
try
{
Initialize.StopScheduler();
}
catch (Exception e)
{
Logger.Error(e);
}
// Shutdown Lucene, but not when we are installing
var appStatus = new ApplicationStatusInfo(new Application());
if (appStatus.Status != UpgradeStatus.Install)
{
Logger.Trace("Disposing Lucene");
if (LuceneController.Instance is IDisposable lucene)
{
lucene.Dispose();
}
}
Logger.Trace("Dumping all Application Errors");
if (HttpContext.Current != null)
{
if (HttpContext.Current.AllErrors != null)
{
foreach (Exception exc in HttpContext.Current.AllErrors)
{
Logger.Fatal(exc);
}
}
}
Logger.Trace("End Dumping all Application Errors");
Logger.Info("Application Ended");
}
private void Application_Start(object sender, EventArgs eventArgs)
{
Logger.InfoFormat(CultureInfo.InvariantCulture, "Application Starting ({0})", Globals.ElapsedSinceAppStart); // just to start the timer
var name = Config.GetSetting("ServerName");
Globals.ServerName = string.IsNullOrEmpty(name) ? Dns.GetHostName() : name;
Logger.InfoFormat(CultureInfo.InvariantCulture, "Application Started ({0})", Globals.ElapsedSinceAppStart); // just to start the timer
DotNetNukeShutdownOverload.InitializeFcnSettings(new ApplicationStatusInfo(new Application()));
// register the assembly-lookup to correct the breaking rename in DNN 9.2
DotNetNuke.Services.Zip.SharpZipLibRedirect.RegisterSharpZipLibRedirect();
////DotNetNukeSecurity.Initialize();
}
private void Application_Error(object sender, EventArgs eventArgs)
{
// Code that runs when an unhandled error occurs
if (HttpContext.Current != null)
{
// Get the exception object.
Logger.Trace("Dumping all Application Errors");
foreach (Exception exc in HttpContext.Current.AllErrors)
{
Logger.Fatal(exc);
}
Logger.Trace("End Dumping all Application Errors");
}
}
private void Application_BeginRequest(object sender, EventArgs e)
{
var app = (HttpApplication)sender;
var authCookie = app.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null && !IsInstallOrUpgradeRequest(app.Request))
{
// if the cookie is not in the database, then it is from before upgrading to 9.2.0 and don't fail
var persisted = AuthCookieController.Instance.Find(authCookie.Value);
if (persisted != null && persisted.ExpiresOn <= DateTime.UtcNow)
{
app.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddDays(-1);
}
}
var requestUrl = app.Request.Url.LocalPath;
if (!requestUrl.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase) && !requestUrl.EndsWith("/", StringComparison.Ordinal) && Endings.Any(ending => requestUrl.EndsWith(ending, StringComparison.OrdinalIgnoreCase)))
{
return;
}
if (IsInstallInProgress(app))
{
return;
}
Initialize.Init(app);
Initialize.RunSchedule(app.Request);
}
private void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
if (HttpContext.Current != null && HttpContext.Current.Handler is PageBase)
{
var page = HttpContext.Current.Handler as PageBase;
page.HeaderIsWritten = true;
}
}
}
}