Update
Since you want to write an HttpModule that imitates System.Web.Routing very accurately, maybe you should use ILSpy and flip the assembly and see what it does?
Original answer (saved for posterity)
It is unclear if you are talking about ASP.NET MVC or Spring MVC or Spring.NET extensions to ASP.NET MVC. If this is the first or third:
For your first example:
Admin/{*}
Decision No. 1 below will consider it. For your second example:
Products/{*}/Search , solution No. 2 will contact him (if there is a need to check or really have something valid there)
Two solutions:
- Create routes that accept these parameters (but don't do anything with them or care about them)
- Create an ActionFilter that validates the request for these parameters (from the route), and then replaces them with what should actually be there.
Solution 1
In the section of your routes in global.asax.cs :
routes.MapRoute("AdminAnything", "Admin/{*anything}", new { controller = admin, action = "Show" } );
This will cause the following URLs to be allowed for the "Show" action in the administrator controller (thus, ignoring the entries as you wish):
Admin/Options Admin/Anything-I-Want-here
Decision 2
Now the second is more complicated because you have something in between.
Input Example:
Product/{*}/Search
You can write an ActionFilter that intercepts the request, looks at it, and replaces that value with whatever you want.
First, the desired route:
routes.MapRoute("ProductSearch", "Products/{searchType}/Search, new { controller = "Products", action = "Search" } );
Then the action of your controller:
public ActionResult Search(string searchType) {
If you want to replace something, you can send the hidden form field in your view and handle this in the Actionfilter:
public class SearchValidationActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if(filterContext.ActionParameters.ContainsKey("searchType") && filterContext.HttpContext.Request.Headers["hiddenSearchType"].IsNotNullOrEmpty())) { var actualSearchType = filterContext.ActionParameters["hiddenSearchType"] as SearchType; var searchType = filterContext.ActionParameters["searchType"]; if (actualSearchType != null) { if (searchType.IsNullOrEmpty()) { filterContext.Result = new SearchRedirectResult(actualSearchType.Name); } else if (!actualSearchType.Name.Equals(searchType)) { filterContext.Result = new SearchRedirectResult(actualSearchType.Name,); } } } base.OnActionExecuting(filterContext); } }
Basically, Decision No. 2 takes whatever you want and, based on the type of hidden search, passes this to the actual type of search.