Yesterday, a classmate asked about adding a custom routing instance to the routes collection, and the problem with her was this:
1. Because you want to add an instance to the routes table when the application is hostile, you need to write the code in the RegisterRoutes method of the global class, and the code is as follows in two ways:
Routes. ADD ("s", New Route ("A/b", New Webformroutehandler ("~/webform1.aspx"));
Routes. ADD ("A", New Route ("c/b", new RouteValueDictionary {{"Controller", "Default"}, {"Home", "Index"}}, New Webformrouteh Andler ("~/webform1.aspx"));
Where A is the name of the route, route is an instance of the route, and a Webformroutehandler custom class is used to process a virtual path and assign it to an actual address, as follows:
public class Webformroutehandler:mvcroutehandler
{
private string virtualpath;
Public Webformroutehandler (string path)
{
virtualpath = path;
}
protected override IHttpHandler Gethttphandler (RequestContext requestcontext)
{
var page = Buildmanager.createinstancefromvirtualpath (VirtualPath, typeof (Page)) as IHttpHandler;
return page;
}
Her problem is that, with the first method above, when doing redirecttoaction (), it will jump directly to the WebForm1.aspx page, while using the second way, then normal, only when accessing the c/b, will access the page.
In contrast to the above two pieces of code, in fact, the second way is just one more example of the RouteValueDictionary class, Microsoft's official definition of this example:
Represents a collection of case-insensitive key/value pairs that you can use in different locations in the routing framework (for example, when you define a default value for a route or when you generate a URL that is based on a route).
In fact, the creation of this object, can be a URL that is c/b defined a default access rules, then the URL will certainly follow this rule to access the specified page.
This article is from the "Zhang Jian Technical column" blog, please be sure to keep this source http://jianle.blog.51cto.com/429692/727680