Repository navigation
Expand file tree
/
Copy pathProfilerHttpModule.cs
More file actions
72 lines (60 loc) · 1.66 KB
/
Copy pathProfilerHttpModule.cs
File metadata and controls
72 lines (60 loc) · 1.66 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
using System;
using System.Web;
using SmartStore.Core.Infrastructure;
using StackExchange.Profiling;
namespace SmartStore.DevTools
{
public class ProfilerHttpModule : IHttpModule
{
private const string MP_KEY = "sm.miniprofiler.started";
public void Init(HttpApplication context)
{
context.BeginRequest += OnBeginRequest;
context.EndRequest += OnEndRequest;
}
public static void OnBeginRequest(object sender, EventArgs e)
{
var app = (HttpApplication)sender;
if (ShouldProfile(app))
{
MiniProfiler.Start();
if (app.Context != null && app.Context.Items != null)
{
app.Context.Items[MP_KEY] = true;
}
}
}
public static void OnEndRequest(object sender, EventArgs e)
{
var app = (HttpApplication)sender;
if (app.Context != null && app.Context.Items != null && app.Context.Items.Contains(MP_KEY))
{
MiniProfiler.Stop();
}
}
private static bool ShouldProfile(HttpApplication app)
{
if (app.Context == null || app.Context.Request == null)
return false;
var url = app.Context.Request.AppRelativeCurrentExecutionFilePath;
if (url.StartsWith("~/admin", StringComparison.InvariantCultureIgnoreCase) || url.StartsWith("~/mini-profiler", StringComparison.InvariantCultureIgnoreCase) || url.StartsWith("~/bundles", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
ProfilerSettings settings;
if (!EngineContext.Current.ContainerManager.TryResolve<ProfilerSettings>(null, out settings))
{
return false;
}
if (!settings.EnableMiniProfilerInPublicStore)
{
return false;
}
return true;
}
public void Dispose()
{
// nothing to dispose
}
}
}