/// <summary> /// Gets the best match for the path and verb. /// </summary> /// <param name="virtualPath">The virtual path.</param> /// <param name="verb">The HTTP verb.</param> /// <returns>A ServicePointMapElement for the arguments.</returns> public ServicePointMapElement GetBestMatch(string virtualPath, string verb) { ServicePointMapElement ele = null; int matchVal, eleVal = -1; for (int i = 0; i < _map.Count; i++) { matchVal = _map[i].ServicePoint.GetMatchRate(virtualPath, verb); if (matchVal > 0) { if (ele == null) { ele = _map[i]; eleVal = matchVal; } else { if (eleVal < matchVal) { ele = _map[i]; eleVal = matchVal; } else if (eleVal == matchVal) { if (ele.ServicePoint.Verb == _map[i].ServicePoint.Verb) { throw new Exception("Identical path match is invalid"); } if (ele.ServicePoint.Verb == ServicePointAttribute.VerbType.ALL) { // Specific takes priority - new wins ele = _map[i]; eleVal = matchVal; } else if (_map[i].ServicePoint.Verb == ServicePointAttribute.VerbType.ALL) { // Specific takes priority - old wins ~ do nothing } else { throw new Exception("Identical path match is invalid"); } } } } } return(ele); }
/// <summary> /// Called when a HTTP request begins. /// </summary> /// <param name="s">The sender (<see cref="HttpApplication"/>).</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> public void OnBeginRequest(Object s, EventArgs e) { HttpApplication app = (HttpApplication)s; ServicePointMapElement ele = _map.GetBestMatch(app.Request.Url.PathAndQuery, app.Request.HttpMethod); Logger.General.Debug("Request received for: " + app.Request.Url.ToString()); if (ele != null) { Logger.General.Debug("Handler method found: " + ele.MethodInfo.Name); ele.MethodInfo.Invoke(_handler, new object[] { app }); } else { Logger.General.Debug("No handler method was found for " + app.Request.Url.ToString()); } }