Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
Created February 4, 2014 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DinisCruz/8805885 to your computer and use it in GitHub Desktop.
Save DinisCruz/8805885 to your computer and use it in GitHub Desktop.
Razor page that list the current mapped HttpHandlers
@using System
@using System.Web
@using System.ComponentModel
@using TeamMentor.CoreLib
@using O2.DotNetWrappers.ExtensionMethods
@{
var application = HttpContextFactory.Context.ApplicationInstance;
var eventHandlerList = (EventHandlerList)application.prop("Events");
var eventsFields = typeof(HttpApplication).fields().where(field=>field.Name.starts("Event"))
.OrderBy(field => field.Name).toList(); ;
var eventsMappings = new Dictionary<String,Object>();
foreach(var field in eventsFields)
{
var eventName = @field.Name.remove("Event");
var eventObject = typeof(HttpApplication).fieldValue(field.Name);
var listEntry = eventHandlerList.invoke("Find",eventObject);
eventsMappings.add(eventName, listEntry );
}
}
<h3>Current ASP.NET Event handlers mapped in the current ASP.NET HttpHander pipeline</h3>
See this gist for more details: https://gist.github.com/DinisCruz/8787331#file-7-find-all-event-objects-cs on the code used
<h3>Table with articles marked for deletion</h3>
<table class="table table-striped table-condensed">
<tr>
<th>Event Name</th>
<th>Callbacks</th>
<th>Target</th>
<th>Method</th>
</tr>
@foreach(var mapping in eventsMappings)
{
if(mapping.Value == null)
{
<tr class='error'>
<td>@mapping.Key</td>
<td colspan=4>0 handlers</td>
</tr>
}
else
{
var handler = mapping.Value.field("handler");
var invocationList = (Delegate[])handler.invoke("GetInvocationList");
var eventMapping = "";
var size = invocationList.size();
if (size==1)
{
<tr class='success'>
<td rowspan='@size'>@mapping.Key</td>
<td rowspan='@size'>@size</td>
<td>@handler.prop("Target")</td>
<td>@handler.prop("Method")</td>
</tr>
}
else
{
for(int i =0 ; i < invocationList.size() ; i++)
{
<tr class='success'>
@if(i==0)
{
<td rowspan='@size'>@mapping.Key</td>
<td rowspan='@size'>@size</td>
}
<td>@invocationList[i].Target</td>
<td>@invocationList[i].Method</td>
</tr>
}
}
}
}
</table>
<h3>Internal objects used</h3>
<pre>
Application : @application
EventHandlerList : @eventHandlerList
# of Events Fields: @eventsFields.size()
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment