MongoDB3.4 Shell CRUD Operations

Source: Internet
Author: User

For an ASP. NET Web Forms application, the requested URL corresponds to a specific physical file (http://xxx.com/default.aspx). Such URLs are tightly bound to specific physical files, bringing many convenient limitations: readability, SEO optimization, and more. To address these limitations, Microsoft introduced a URL routing system. The following is a demo to dissect the routing system of ASP.

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

650) this.width= 650, "src="/img/fz.gif "alt=" Copy Code "style=" border:none;margin:0px;padding:0px; "/>

public class global : system.web.httpapplication    {         protected void application_start (object sender,  Eventargs e)         {             //Processing matching files              RouteTable.Routes.RouteExistingFiles = true;             //url Default Value              Routevaluedictionary defaults = new routevaluedictionary ()  { {  "name",   "Wuwenmao"  }, {  "id",  "001"  } };             //Routing Constraints              routevaluedictionary constraints = new routevaluedictionary ()  { {  "name",  @ "\w{2,10}"  }, {  "id",  @ "\d{3}"  } };            //value associated with the route , but does 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);         }    }

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:none;margin:0px;padding:0px; "/>

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

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:none;margin:0px;padding:0px; "/>

<%@ page language= "C #"  autoeventwireup= "true"  codebehind= "Default.aspx.cs"   inherits= "Webapplication2.default"  %><! doctype html>

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:none;margin:0px;padding:0px; "/>

The input path is three and the results are the same:

http://localhost:2947/employees/wuwenmao/001

Http://localhost:2947/employees/wuwenmao

http://localhost:2947/employees/

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214163333410-2067488418.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

The reason is that the default values are set for the variables in the routing template when the route is registered, so it is equivalent when using the three URLs above.

Looking back at the global file, a variable was also set when registering the route:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214163838285-1776356528.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

This is the use of regular rules to qualify the value of the variable in the routing template, the corresponding variable value in the request URL can only be correctly requested, otherwise 404 error is returned. If the ID value is longer than 3 o'clock:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214164122707-1107978194.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

Above through a simple example of the ASP. NET routing system, below we look through the source code to analyze the implementation of the ASP.

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

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214164901582-1207096860.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

With the reflector tool, we can see:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214165312722-1962205551.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

Now there is a problem, after registering a good route, how does ASP. NET use the routing system? As a matter of fact The ASP. NET routing system is by registering a HttpModule object, which is implemented by the HttpModule object to intercept the request, then dynamically mapped to the HttpHandler object used to process the current request, and finally the request is processed and responded to by the HttpHandler object. This httpmodule is actually urlroutingmodule, When we start the ASP, we can verify by using the Modules property in the global file, and as you can see, the Modules property contains the registered HttpModule, which contains urlroutingmodule:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214172625629-734507210.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

In this urlroutingmodule, and what to do with the route-related operations, we continue to look at the source code:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214171123050-1998022123.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170214171250550-1762176555.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170215085919754-441033997.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

Through the above source view, we can see that when the request came, The ASP. NET intercepts the request by registering the UrlRoutingModule module, then finds the matching routedata from the Global routing table, retrieves the corresponding HttpHandler according to HttpApplication if found, and maps it to the current request context for subsequent The pipeline event is used to process the current request.

Below we continue to look at the source code, analyze how urlroutingmodule from the Global routing table to get Routedata:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170215091340285-1798550042.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

As you can see from the above, the getroutedata that calls the global route table in UrlRoutingModule actually calls the getroutedata of each route registered, returns the first matching routedata, and if the registered routes do not match, Returns NULL.

Now let's look at what the Getroutedata in the route did:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170215092558066-1895291496.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

Match method:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170215093044847-1112160679.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1002347/201702/ 1002347-20170215093109707-1243607066.png "style=" border:none;height:auto;margin:0px;padding:0px; "/>

By calling the route's Getroutedata method in turn, the following actions are done in the Getroutedata method:

1. Call the match method of the Parsedroute type to make the matching work of the request URL and the route template registered in the current route object, if there is no match, return null directly;

2, if the request URL and the current route object's route template matches, the common Routedata object;

3, according to the constraints defined when registering routing information to verify whether the current request URL passed, not by returning null;

4, for the Routedata object of values and Datatokens assignment operation;

5, return Routedata object;

In this way, the routing system is basically analyzed, and many details are limited to one by one analysis.

Summarize:

through the above analysis, we tidy up the idea, A summary of the work done on the ASP: first, we register the route object in global and then intercept the request URL by urlroutingmodule The HttpModule module in the ASP. NET, and then from the Global routing table routetables.ro Utes calls the getroutedata of the route object in turn to match the request URL and the registration routing information, returning the first matching routedata, After finding the complete routetables.routes, there is no match, return null, and eventually return 404 to the front page


MongoDB3.4 Shell CRUD Operations

Related Article

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.