-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorPage.aspx.cs
executable file
·192 lines (176 loc) · 8.09 KB
/
ErrorPage.aspx.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
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
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2013
// by DotNetNuke Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
#region Usings
using System;
using System.Web;
using System.Web.UI;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Security;
using DotNetNuke.Services.FileSystem;
#endregion
// ReSharper disable CheckNamespace
namespace DotNetNuke.Services.Exceptions
// ReSharper restore CheckNamespace
{
/// -----------------------------------------------------------------------------
/// Project : DotNetNuke
/// Class : ErrorPage
///
/// -----------------------------------------------------------------------------
/// <summary>
/// Trapped errors are redirected to this universal error page, resulting in a
/// graceful display.
/// </summary>
/// <remarks>
/// 'get the last server error
/// 'process this error using the Exception Management Application Block
/// 'add to a placeholder and place on page
/// 'catch direct access - No exception was found...you shouldn't end up here unless you go to this aspx page URL directly
/// </remarks>
/// <history>
/// [sun1] 1/19/2004 Created
/// </history>
/// -----------------------------------------------------------------------------
public partial class ErrorPage : Page
{
private void ManageError(string status)
{
string errorMode = Config.GetCustomErrorMode();
string errorMessage = HttpUtility.HtmlEncode(Request.QueryString["error"]);
string errorMessage2 = HttpUtility.HtmlEncode(Request.QueryString["error2"]);
string localizedMessage = Localization.Localization.GetString(status + ".Error", Localization.Localization.GlobalResourceFile);
if (localizedMessage != null)
{
localizedMessage = localizedMessage.Replace("src=\"images/403-3.gif\"", "src=\"" + ResolveUrl("~/images/403-3.gif") + "\"");
if (!string.IsNullOrEmpty(errorMessage2) && ( (errorMode=="Off") || ( (errorMode=="RemoteOnly") && (Request.IsLocal) ) ))
{
ErrorPlaceHolder.Controls.Add(new LiteralControl(string.Format(localizedMessage, errorMessage2)));
}
else
{
ErrorPlaceHolder.Controls.Add(new LiteralControl(string.Format(localizedMessage, errorMessage)));
}
}
int statusCode;
Int32.TryParse(status, out statusCode);
if (statusCode > -1)
{
Response.StatusCode = statusCode;
}
}
[Obsolete("Function obsoleted in 5.6.1 as no longer used in core - version identification can be useful to potential hackers if used incorrectly")]
public string ExtractOSVersion()
{
//default name to OSVersion in case OS not recognised
string commonName = Environment.OSVersion.ToString();
switch (Environment.OSVersion.Version.Major)
{
case 5:
switch (Environment.OSVersion.Version.Minor)
{
case 0:
commonName = "Windows 2000";
break;
case 1:
commonName = "Windows XP";
break;
case 2:
commonName = "Windows Server 2003";
break;
}
break;
case 6:
switch (Environment.OSVersion.Version.Minor)
{
case 0:
commonName = "Windows Vista";
break;
case 1:
commonName = "Windows Server 2008";
break;
case 2:
commonName = "Windows 7";
break;
}
break;
}
return commonName;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
DefaultStylesheet.Attributes["href"] = ResolveUrl("~/Portals/_default/default.css");
InstallStylesheet.Attributes["href"] = ResolveUrl("~/Install/install.css");
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
PortalSettings portalSettings = PortalController.GetCurrentPortalSettings();
if (portalSettings != null && !String.IsNullOrEmpty(portalSettings.LogoFile))
{
IFileInfo fileInfo = FileManager.Instance.GetFile(portalSettings.PortalId, portalSettings.LogoFile);
if (fileInfo != null)
{
headerImage.ImageUrl = FileManager.Instance.GetUrl(fileInfo);
}
}
headerImage.Visible = !string.IsNullOrEmpty(headerImage.ImageUrl);
string localizedMessage;
var security = new PortalSecurity();
string status = security.InputFilter(Request.QueryString["status"],
PortalSecurity.FilterFlag.NoScripting |
PortalSecurity.FilterFlag.NoMarkup);
if (!string.IsNullOrEmpty(status))
ManageError(status);
else
{
//get the last server error
var exc = Server.GetLastError();
try
{
if (Request.Url.LocalPath.ToLower().EndsWith("installwizard.aspx"))
{
ErrorPlaceHolder.Controls.Add(new LiteralControl(HttpUtility.HtmlEncode(exc.ToString())));
}
else
{
var lex = new PageLoadException(exc.Message, exc);
Exceptions.LogException(lex);
localizedMessage = Localization.Localization.GetString("Error.Text", Localization.Localization.GlobalResourceFile);
ErrorPlaceHolder.Controls.Add(new ErrorContainer(portalSettings, localizedMessage, lex).Container);
}
}
catch
{
//No exception was found...you shouldn't end up here
//unless you go to this aspx page URL directly
localizedMessage = Localization.Localization.GetString("UnhandledError.Text", Localization.Localization.GlobalResourceFile);
ErrorPlaceHolder.Controls.Add(new LiteralControl(localizedMessage));
}
Response.StatusCode = 500;
}
localizedMessage = Localization.Localization.GetString("Return.Text", Localization.Localization.GlobalResourceFile);
hypReturn.Text = localizedMessage;
}
}
}