Using the .net core middleware

Widely used in .net core in the injection, middleware, injected in the previous article write, here we introduce the use of middleware.

I am using the middleware needs is access to a static resource files with the console program, .net core web applications with an integrated, used here is the console program, needs its own access.

 

The first step to create a middleware processing class:

 

 

 This is a javascript to access middleware, first determines whether the request address js file, if not then go directly to the next intermediate pipe, if it is found corresponding to the local file, then the output from the pipe.

The second step is to create a middleware, which is kind of middleware class call processing

 

 

The third step is to type the following code in the Startup folder in the introduction to middleware, so that when the request reaches the server will automatically call middleware

 

 Here access to the entire middleware has been completed. Still commonplace word: this function is not to have to use, but when the need of re-access. For example, authentication, can use the middleware to achieve, but a better solution is to use MVC filters.

 

 , Some to join me here is to focus on each controller used in a feature class or method, both can be achieved, I think the focus is more convenient, but lost flexibility

 

Guess you like

Origin www.cnblogs.com/zlheb/p/11618905.html