Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MongoDB3.4 shell CRUD operation

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

MongoDB3.4 shell CRUD operation, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

For Asp.Net Web Forms applications, the requested Url corresponds to a specific physical file (http://xxx.com/default.aspx). Such Url is closely tied to specific physical files, which brings a lot of convenient limitations: readability, SEO optimization, and so on. In order to solve these limitations, Microsoft introduced URL routing system. Let's analyze the routing system of Asp.Net through a Demo.

Create an empty WebForm application and add the following code to the Global.asax.cs file:

Public class Global: System.Web.HttpApplication {protected void Application_Start (object sender, EventArgs e) {/ / process matching files RouteTable.Routes.RouteExistingFiles = true; / / url default RouteValueDictionary defaults = new RouteValueDictionary () {{"name", "wuwenmao"}, {"id", "001"}} / / routing constraint RouteValueDictionary constraints = new RouteValueDictionary () {{"name", @ "\ w {2pm 10}"}, {"id", @ "\ d {3}"}} / / values related to the route, but do not participate in whether the route matches the URL pattern RouteValueDictionary dataTokens = new RouteValueDictionary () {{"defaultName", "wuwenmao"}, {"defaultId", "001"}}; RouteTable.Routes.MapPageRoute ("default", "employees/ {name} / {id}", "~ / Default.aspx", false, defaults, constraints, dataTokens);}}

Create a new WebForm page named Default with the following code:

This is the DataTokens: = in Values: = RouteData in the Default.aspx page RouteData

Enter the following three paths, and the result is the same:

Http://localhost:2947/employees/wuwenmao/001

Http://localhost:2947/employees/wuwenmao

Http://localhost:2947/employees/

The reason is that when registering a route, the default value is set for the variables in the route template, so it is equivalent when using the above three url.

Looking back at the Global file, you also set a variable when registering the route:

This is the use of regular rules to define the value of variables in the routing template, and the corresponding variable values in the request url can only be correctly requested if they match the rules, otherwise a 404 error will be returned. If the length of id value is greater than 3:

Above through a simple example to experience the Asp.Net routing system, let's look at the source code to analyze the implementation principle of the Asp.Net routing system.

First, when we register a route in our Global file using the following statement, we are actually adding a route to the global routing table.

Through the Reflector tool, we can see:

Now the question is, how does Asp.Net use the routing system after registering the route? In fact, the Asp.Net routing system registers a HttpModule object, which intercepts the request, then dynamically maps it to the HttpHandler object used to process the current request, and finally processes and responds to the request through the HttpHandler object. This HttpModule is actually UrlRoutingModule. When we start the Asp.Net program, we can verify it through the Modules attribute in the Global file. You can see from the screenshot below that the Modules attribute contains the registered HttpModule, including UrlRoutingModule:

What routing-related operations have been done in this UrlRoutingModule? let's continue to look at the source code:

From the source code view above, we can see that when a request comes, Asp.Net intercepts the request through the registered UrlRoutingModule module, and then looks for a matching RouteData from the global routing table. If it can be found, it gets the corresponding HttpHandler according to the HttpApplication, and then maps it to the current request context for subsequent pipeline events to process the current request.

Let's continue to look at the source code and analyze how UrlRoutingModule obtains RouteData from the global routing table:

As you can see above, calling the GetRouteData of the global routing table in UrlRoutingModule actually calls the GetRouteData of each registered Route in turn and returns the first matching RouteData. If none of the registered routes match, null is returned.

Let's take a look at what GetRouteData does in Route:

Match method:

By calling the GetRouteData method of Route in turn, you do the following in the GetRouteData method:

1. The Match method of type ParsedRoute is called to match the request Url with the routing template registered in the current Route object. If there is no match, return null directly.

2. If the request Url matches the routing template of the current Route object, the common RouteData object

3. Verify whether the current request Url is passed according to the constraints defined when registering routing information, not by returning null

4. Assign values to Values and DataTokens of RouteData object

5. Return the RouteData object

At this point, the routing system of Asp.Net has basically been analyzed, and there are still many details that cannot be analyzed one by one due to the limitation of space.

Summary:

Through the above analysis, we sort out our ideas and summarize the work done by the Asp.Net routing system: first, we register the Route object in Global, then intercept the request Url through the HttpModule module UrlRoutingModule registered in Asp.Net, and then call the GetRouteData of the Route object from the global routing table RouteTables.Routes to match the request Url and registered routing information, and return the first matching RouteData After searching the entire RouteTables.Routes, there is no match. Return null, which will eventually return 404 to the front-end page.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report