Learn the ASP. MVC5 Framework Secret Note-asp.net Routing (iv)

Source: Internet
Author: User

2.RouteData

Let's take a look at the same time for encapsulating routing data as getroutedata method return value of routedata routedata Has a property of type routebase route This property returns a generation of this Span style= "Font-family:times New Roman" >routedata route object. But this is a readable / Write properties that we can use any one of the route object to assign this property.

public class Routedata{public Routedata ();p ublic routedata (routebase route,iroutehandler routehandler);p ublic string Getrequiredstring (String valueName);p ublic routebase Route {set; get;} Public Iroutehandler Routehandler {set; get;} Public routevaluedictionary Values {get;} Public routevaluedictionary Datatokens {get;}}

Routedataof theValuesand theDatatokensproperty returns aRouteValueDictionarythe object. RouteValueDictionaryis a realization of theidictionary<string,object>the dictionary of the interface. ASPThis object is used by the routing system to hold the route variable, the dictionary elementKeyand theValuerepresents the name and value of a variable, respectively. stored inValuesand theDatatokensThe difference between the routing variables in these two properties is that the former passes the requestURLis parsed, and the latter is a custom variable that is directly attached to the routing object.

In some of the routing scenarios, we're going toRouteA collection of variables that are parsed on the request for routing (Valuesattribute) must contain variable values for certain fixed names, such asASP . NET MVCthe application representsControllerand theActionname of the variable),Routedataof thegetrequiredstringmethods are used to get their values. For the invocation of the method, if the variable of the specified name is in theValuesproperty does not exist, it directly throws aInvalidOperationExceptionexception.

Routedatathrough itsRoutehandlerproperty returns aRoutehandlerobject. Routehandlerhas an important role in the entire routing system, as it is ultimately used to process the requestedHttpHandlerThe object is provided by it, and all theRoutehandlertypes are implemented with the following definitions.Iroutehandlerinterface,HttpHandlerthe provided implementations in itsGethttphandlermethod. We can do this in the constructor.Routedataof theRoutehandlerproperty is initialized, or it can be read directly to the/The Write property is assigned.

public interface Iroutehandler{ihttphandler Gethttphandler (RequestContext requestcontext);}
when a request is successfully routed to a . aspxpage, by calling the matchRouteobject thatGetroutedatamethod generates aRoutedatais directly attached to the target page corresponding to thepageobject. Pagehas a type ofRoutedataA read-only property of the same name, which returns exactly thisRoutedataobject.

Learn the ASP. MVC5 Framework Secret Note-asp.net Routing (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.