-
Notifications
You must be signed in to change notification settings - Fork 0
/
MvcDiagnostics.aspx
327 lines (285 loc) · 17.7 KB
/
MvcDiagnostics.aspx
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Security" %>
<%@ Import Namespace="System.Web.Compilation" %>
<script runat="server">
private static readonly DateTime _utilityDate = new DateTime(2010, 2, 16);
private static readonly string _utilityVersion = "v7";
private static readonly string _defaultFuturesDownloadUrl = "http://aspnet.codeplex.com/";
private static readonly MvcCoreAssemblyInfo[] _mvcCoreAssemblyHistory = new MvcCoreAssemblyInfo[] {
// v1
new MvcCoreAssemblyInfo() { Version = "1.0.30218.0", Name = "ASP.NET MVC 1.0 Preview 2" },
new MvcCoreAssemblyInfo() { Version = "1.0.30508.0", Name = "ASP.NET MVC 1.0 Preview 3" },
new MvcCoreAssemblyInfo() { Version = "1.0.30714.0", Name = "ASP.NET MVC 1.0 Preview 4" },
new MvcCoreAssemblyInfo() { Version = "1.0.30826.0", Name = "ASP.NET MVC 1.0 Preview 5" },
new MvcCoreAssemblyInfo() { Version = "1.0.31003.0", Name = "ASP.NET MVC 1.0 Beta" },
new MvcCoreAssemblyInfo() { Version = "1.0.40112.0", Name = "ASP.NET MVC 1.0 RC 1" },
new MvcCoreAssemblyInfo() { Version = "1.0.40128.0", Name = "ASP.NET MVC 1.0 RC 1 Refresh" },
new MvcCoreAssemblyInfo() { Version = "1.0.40216.0", Name = "ASP.NET MVC 1.0 RC 2" },
new MvcCoreAssemblyInfo() { Version = "1.0.40310.0", Name = "ASP.NET MVC 1.0 RTM", FuturesVersion = "1.0.40310.0" },
// v2
new MvcCoreAssemblyInfo() { Version = "1.1.40430.0", Name = "ASP.NET MVC 1.1 Preview 0" },
new MvcCoreAssemblyInfo() { Version = "2.0.40724.0", Name = "ASP.NET MVC 2 Preview 1", FuturesVersion = "2.0.40724.0" },
new MvcCoreAssemblyInfo() { Version = "2.0.41001.0", Name = "ASP.NET MVC 2 Preview 2", FuturesVersion = "2.0.41001.0" },
new MvcCoreAssemblyInfo() { Version = "2.0.41116.0", Name = "ASP.NET MVC 2 Beta", FuturesVersion = "2.0.41116.0" },
new MvcCoreAssemblyInfo() { Version = "2.0.41211.0", Name = "ASP.NET MVC 2 RC 1", FuturesVersion = "2.0.41211.0" },
new MvcCoreAssemblyInfo() { Version = "2.0.50129.0", Name = "ASP.NET MVC 2 RC 2", FuturesVersion = "2.0.50129.0" },
new MvcCoreAssemblyInfo() { Version = "2.0.50217.0", Name = "ASP.NET MVC 2 RTM", FuturesVersion = "2.0.50217.0" }
};
private static readonly MvcFuturesAssemblyInfo[] _mvcFuturesAssemblyHistory = new MvcFuturesAssemblyInfo[] {
// v1
new MvcFuturesAssemblyInfo() { Version = "1.0.40310.0", Name = "ASP.NET MVC 1.0 RTM Futures", DownloadUrl = "http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471#DownloadId=61773" },
// v2
new MvcFuturesAssemblyInfo() { Version = "2.0.40724.0", Name = "ASP.NET MVC 2 Preview 1 Futures", DownloadUrl = "http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30886#DownloadId=77345" },
new MvcFuturesAssemblyInfo() { Version = "2.0.41001.0", Name = "ASP.NET MVC 2 Preview 2 Futures", DownloadUrl = "http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33836#DownloadId=85929" },
new MvcFuturesAssemblyInfo() { Version = "2.0.41116.0", Name = "ASP.NET MVC 2 Beta Futures", DownloadUrl = "http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36054#DownloadId=93343" },
new MvcFuturesAssemblyInfo() { Version = "2.0.41211.0", Name = "ASP.NET MVC 2 RC 1 Futures", DownloadUrl = "http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=37423#DownloadId=97581" },
new MvcFuturesAssemblyInfo() { Version = "2.0.50129.0", Name = "ASP.NET MVC 2 RC 2 Futures", DownloadUrl = "http://go.microsoft.com/fwlink/?LinkID=183045" },
new MvcFuturesAssemblyInfo() { Version = "2.0.50217.0", Name = "ASP.NET MVC 2 RTM Futures", DownloadUrl = "http://go.microsoft.com/fwlink/?LinkID=183739" }
};
// Diagnostics routines
private class DiagnosticsResults {
public DiagnosticsResults() {
EnvironmentInformation = GetEnvironmentInformation();
AllAssemblies = BuildManager.GetReferencedAssemblies().OfType<Assembly>().Concat(AppDomain.CurrentDomain.GetAssemblies()).Distinct().OrderBy(o => o.FullName).ToArray();
LoadedMvcCoreAssemblies = AllAssemblies.Where(IsMvcAssembly).Select<Assembly, LoadedAssemblyInfo<MvcCoreAssemblyInfo>>(GetMvcAssemblyInformation).ToArray();
LoadedMvcFuturesAssemblies = AllAssemblies.Where(IsMvcFuturesAssembly).Select<Assembly, LoadedAssemblyInfo<MvcFuturesAssemblyInfo>>(GetFuturesAssemblyInformation).ToArray();
IsFuturesConflict = (LoadedMvcCoreAssemblies.Length == 1 && LoadedMvcFuturesAssemblies.Length == 1 && LoadedMvcCoreAssemblies[0].MvcAssemblyInfo.FuturesVersion != LoadedMvcFuturesAssemblies[0].MvcAssemblyInfo.Version);
IsError = (LoadedMvcCoreAssemblies.Length != 1) || (LoadedMvcFuturesAssemblies.Length > 1) || IsFuturesConflict;
}
private static EnvironmentInformation GetEnvironmentInformation() {
string iisVersion = HttpContext.Current.Request.ServerVariables["SERVER_SOFTWARE"];
if (String.IsNullOrEmpty(iisVersion)) {
iisVersion = "{ not available }";
}
string processName = "{ not available }";
try {
// late binding so that LinkDemands are not triggered
object currentProcess = typeof(Process).GetMethod("GetCurrentProcess", Type.EmptyTypes).Invoke(null, null);
object processModule = typeof(Process).GetProperty("MainModule").GetValue(currentProcess, null);
processName = (string)typeof(ProcessModule).GetProperty("ModuleName").GetValue(processModule, null);
}
catch { } // swallow exceptions
return new EnvironmentInformation() {
OperatingSystem = Environment.OSVersion,
NetFrameworkVersion = Environment.Version,
NetFrameworkBitness = IntPtr.Size * 8,
ServerSoftware = iisVersion,
WorkerProcess = processName,
IsIntegrated = HttpRuntime.UsingIntegratedPipeline
};
}
private static void PopulateLoadedAssemblyBaseInformation(LoadedAssemblyInfoBase assemblyInfo, Assembly assembly) {
string codeBase = "{ not available }";
try {
codeBase = assembly.CodeBase;
}
catch (SecurityException) {
// can't read code base in medium trust, so just skip
}
string deployment = (assembly.GlobalAssemblyCache) ? "GAC" : "bin";
assemblyInfo.CodeBase = codeBase;
assemblyInfo.Deployment = deployment;
assemblyInfo.FullName = assembly.FullName;
}
private static LoadedAssemblyInfo<MvcCoreAssemblyInfo> GetMvcAssemblyInformation(Assembly assembly) {
AssemblyFileVersionAttribute fileVersionAttr = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true /* inherit */).OfType<AssemblyFileVersionAttribute>().FirstOrDefault();
string actualVersion = (fileVersionAttr != null) ? fileVersionAttr.Version : "no version";
string friendlyName = "Unknown version";
MvcCoreAssemblyInfo matchingCore = _mvcCoreAssemblyHistory.Where(c => String.Equals(actualVersion, c.Version)).FirstOrDefault();
if (matchingCore == null) {
matchingCore = new MvcCoreAssemblyInfo() {
Name = friendlyName,
Version = actualVersion
};
}
LoadedAssemblyInfo<MvcCoreAssemblyInfo> assemblyInfo = new LoadedAssemblyInfo<MvcCoreAssemblyInfo>() {
MvcAssemblyInfo = matchingCore
};
PopulateLoadedAssemblyBaseInformation(assemblyInfo, assembly);
return assemblyInfo;
}
private static LoadedAssemblyInfo<MvcFuturesAssemblyInfo> GetFuturesAssemblyInformation(Assembly assembly) {
AssemblyFileVersionAttribute fileVersionAttr = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true /* inherit */).OfType<AssemblyFileVersionAttribute>().FirstOrDefault();
string actualVersion = (fileVersionAttr != null) ? fileVersionAttr.Version : "no version";
string friendlyName = "Unknown version";
MvcFuturesAssemblyInfo matchingCore = _mvcFuturesAssemblyHistory.Where(c => String.Equals(actualVersion, c.Version)).FirstOrDefault();
if (matchingCore == null) {
matchingCore = new MvcFuturesAssemblyInfo() {
Name = friendlyName,
Version = actualVersion
};
}
LoadedAssemblyInfo<MvcFuturesAssemblyInfo> assemblyInfo = new LoadedAssemblyInfo<MvcFuturesAssemblyInfo>() {
MvcAssemblyInfo = matchingCore
};
PopulateLoadedAssemblyBaseInformation(assemblyInfo, assembly);
return assemblyInfo;
}
private static bool IsMvcAssembly(Assembly assembly) {
return (String.Equals(assembly.ManifestModule.Name, "System.Web.Mvc.dll", StringComparison.OrdinalIgnoreCase)
|| (assembly.GetType("System.Web.Mvc.Controller", false /* throwOnError */) != null));
}
private static bool IsMvcFuturesAssembly(Assembly assembly) {
return (String.Equals(assembly.ManifestModule.Name, "Microsoft.Web.Mvc.dll", StringComparison.OrdinalIgnoreCase));
}
public readonly EnvironmentInformation EnvironmentInformation;
public readonly LoadedAssemblyInfo<MvcCoreAssemblyInfo>[] LoadedMvcCoreAssemblies;
public readonly LoadedAssemblyInfo<MvcFuturesAssemblyInfo>[] LoadedMvcFuturesAssemblies;
public readonly Assembly[] AllAssemblies;
public readonly bool IsError;
public readonly bool IsFuturesConflict;
}
private class EnvironmentInformation {
public OperatingSystem OperatingSystem;
public Version NetFrameworkVersion;
public int NetFrameworkBitness;
public string ServerSoftware;
public string WorkerProcess;
public bool IsIntegrated;
}
private class LoadedAssemblyInfo<T> : LoadedAssemblyInfoBase where T : MvcAssemblyInfoBase {
public new T MvcAssemblyInfo {
get {
return (T)(base.MvcAssemblyInfo);
}
set {
base.MvcAssemblyInfo = value;
}
}
}
private class LoadedAssemblyInfoBase {
public MvcAssemblyInfoBase MvcAssemblyInfo;
public string FullName;
public string CodeBase;
public string Deployment;
}
private class MvcCoreAssemblyInfo : MvcAssemblyInfoBase {
public string FuturesVersion;
}
private class MvcFuturesAssemblyInfo : MvcAssemblyInfoBase {
public string DownloadUrl;
}
private class MvcAssemblyInfoBase {
public string Version;
public string Name;
}
private static MvcFuturesAssemblyInfo GetOrCreateFuturesAssemblyInfo(string futuresVersion) {
MvcFuturesAssemblyInfo futuresInfo = _mvcFuturesAssemblyHistory.FirstOrDefault(o => String.Equals(futuresVersion, o.Version, StringComparison.OrdinalIgnoreCase));
return (futuresInfo != null) ? futuresInfo : new MvcFuturesAssemblyInfo() { DownloadUrl = _defaultFuturesDownloadUrl, Name = "ASP.NET MVC Futures", Version = futuresVersion };
}
private static string AE(object input) {
return HttpUtility.HtmlAttributeEncode(Convert.ToString(input, CultureInfo.InvariantCulture));
}
private static string E(object input) {
return HttpUtility.HtmlEncode(Convert.ToString(input, CultureInfo.InvariantCulture));
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET MVC Diagnostics Utility</title>
<style type="text/css">
.error
{
font-weight: bold;
color: Red;
}
.box
{
border-width: thin;
border-style: solid;
padding: .2em 1em .2em 1em;
background-color: #dddddd;
}
.errorInset
{
padding: 1em;
background-color: #ffbbbb;
}
body
{
font-family: Calibri, Helvetica;
}
</style>
</head>
<%
DiagnosticsResults results = new DiagnosticsResults();
Action<LoadedAssemblyInfoBase> outputAssemblyInfo = assemblyInfo => {
%>
<p>
<b>Assembly version:</b> <%= E(assemblyInfo.MvcAssemblyInfo.Name) %> (<%= E(assemblyInfo.MvcAssemblyInfo.Version) %>)<br />
<b>Full name:</b> <%= E(assemblyInfo.FullName) %><br />
<b>Code base:</b> <%= E(assemblyInfo.CodeBase) %><br />
<b>Deployment:</b> <%= E(assemblyInfo.Deployment) %>-deployed
</p>
<% }; %>
<body>
<h1>Microsoft ASP.NET MVC Diagnostics Information</h1>
<p>
This page is designed to help diagnose common errors related to mismatched or conflicting ASP.NET MVC binaries.
If a known issue is identified, it will be displayed below in <span class="error">red</span> text.
</p>
<p>
For questions or problems with ASP.NET MVC or this utility, please visit the ASP.NET MVC forums at <a href="http://forums.asp.net/1146.aspx">http://forums.asp.net/1146.aspx</a>.
</p>
<% if (results.IsError) { %><p class="error">Errors were found. Please see below for more information.</p><% } %>
<h2>Environment Information</h2>
<div class="box">
<p>
<b>Operating system:</b> <%= E(results.EnvironmentInformation.OperatingSystem) %><br />
<b>.NET Framework version:</b> <%= E(results.EnvironmentInformation.NetFrameworkVersion) %> (<%= E(results.EnvironmentInformation.NetFrameworkBitness) %>-bit)<br />
<b>Web server:</b> <%= E(results.EnvironmentInformation.ServerSoftware) %><br />
<b>Integrated pipeline:</b> <%= E(results.EnvironmentInformation.IsIntegrated) %><br />
<b>Worker process:</b> <%= E(results.EnvironmentInformation.WorkerProcess) %>
</p>
</div>
<h2>ASP.NET MVC Assembly Information (System.Web.Mvc.dll)</h2>
<div class="box">
<% if (results.LoadedMvcCoreAssemblies.Length == 0) { %><p class="error">An ASP.NET MVC assembly has not been loaded into this application.</p><% } %>
<% if (results.LoadedMvcCoreAssemblies.Length > 1) { %><p class="error">Multiple ASP.NET MVC assemblies have been loaded into this application.</p><% } %>
<% foreach (var info in results.LoadedMvcCoreAssemblies) { outputAssemblyInfo(info); } %>
</div>
<h2>ASP.NET MVC Futures Assembly Information (Microsoft.Web.Mvc.dll)</h2>
<div class="box">
<% if (results.LoadedMvcFuturesAssemblies.Length == 0) { %>
<p>
An ASP.NET MVC Futures assembly has not been loaded into this application.
<% if (results.LoadedMvcCoreAssemblies.Length == 1) { %>
<% MvcFuturesAssemblyInfo futuresAssemblyInfo = GetOrCreateFuturesAssemblyInfo(results.LoadedMvcCoreAssemblies[0].MvcAssemblyInfo.FuturesVersion); %>
If desired, you can download <%= E(futuresAssemblyInfo.Name) %> from <a href="<%= AE(futuresAssemblyInfo.DownloadUrl) %>"><%= E(futuresAssemblyInfo.DownloadUrl) %></a>.
<% } %>
</p>
<% } %>
<% if (results.LoadedMvcFuturesAssemblies.Length > 1) { %><p class="error">Multiple ASP.NET MVC Futures assemblies have been loaded for this application.</p><% } %>
<% if (results.IsFuturesConflict) { %>
<%-- We know that there's one version of Futures + one version of MVC loaded. --%>
<div>
<p class="error">Mismatched or outdated versions of ASP.NET MVC and ASP.NET MVC Futures are loaded.</p>
<p class="errorInset">
Loaded version of ASP.NET MVC is: <%= E(results.LoadedMvcCoreAssemblies[0].MvcAssemblyInfo.Name)%> (<%= E(results.LoadedMvcCoreAssemblies[0].MvcAssemblyInfo.Version) %>)<br />
Loaded version of ASP.NET MVC Futures is: <%= E(results.LoadedMvcFuturesAssemblies[0].MvcAssemblyInfo.Name) %> (<%= E(results.LoadedMvcFuturesAssemblies[0].MvcAssemblyInfo.Version) %>)<br />
<% MvcFuturesAssemblyInfo futuresAssemblyInfo = GetOrCreateFuturesAssemblyInfo(results.LoadedMvcCoreAssemblies[0].MvcAssemblyInfo.FuturesVersion); %>
Download <%= E(futuresAssemblyInfo.Name) %> from <a href="<%= AE(futuresAssemblyInfo.DownloadUrl) %>"><%= E(futuresAssemblyInfo.DownloadUrl) %></a>.
</p>
</div>
<% } %>
<% foreach (var info in results.LoadedMvcFuturesAssemblies) { outputAssemblyInfo(info); } %>
</div>
<h2>All Loaded Assemblies</h2>
<div class="box">
<p><%= E(results.AllAssemblies.Length) %> assemblies are loaded.</p>
<ul>
<% foreach (Assembly assembly in results.AllAssemblies) { %><li><%= E(assembly) %></li><% } %>
</ul>
</div>
<p>
<b>Diagnostics version:</b> <%= E(_utilityDate) %> <%= E(_utilityVersion) %><br />
<b>Report generated on:</b> <%= E(DateTime.Now) %>
</p>
</body>
</html>