Program model handling IApplicationModelConvention On the instance object of MvcOptions, there is an ApplicationModelConventions property (type: List
View Engine ManagementViewEngines In the instance object of MvcOptions, there is a ViewEngines property that is used to save the system's view engine collection so that we can implement our own custom view engine. For example, in the "Custom View View File Search Logic" chapter, we used this feature to implement our own custom view engine. The example is as follows:
InputFormater/OutputFormater in Web API enter The processing of input parameters of Web API and current MVC currently supports JSON and XML formats. The specific processing classes are as follows:
Output In Web API, there are four default output formatters:
The above four types are automatically judged and output according to different situations in the system. The specific judgment rules are as follows: If the action is similar to the following, use HttpNoContentOutputFormatter to return 204, which means NoContent.
If the following method also returns a string, only the Action whose return type is string will use StringOutputFormatter to return the string; if the Action whose return type is object, use JsonOutputFormatter to return the string data of JSON type.
If neither of the above two types of actions is used, JsonOutputFormatter is used by default to return JSON data. If the JsonOutputFormatter formatter is deleted through the following statement, XmlDataContractSerializerOutputFormatter will be used to return XML data.
Of course, you can also use ProducesAttribute to explicitly declare the use of the JsonOutputFormatter formatter, as shown below.
Alternatively, you can use the ProducesAttribute on the base Controller class, as shown below:
Of course, you can also declare the ProducesAttribute in the global scope, as shown below:
Output Cache and Profile In MVC6, the OutputCache feature is supported by the ResponseCacheAttribute class, as shown below:
The above example indicates that the content of the page will be cached on the client for 100 seconds. In other words, a Cache-Control header is added to the Response header and max-age=100 is set. The following are the attributes supported by this feature: In addition, ResponseCacheAttribute also supports a CacheProfileName attribute so that the globally set profile information configuration can be read for caching. The example is as follows:
By adding a personality setting named MyProfile to the CacheProfiles property value of MvcOptions, you can use this configuration information on all Actions. Other things we are already familiar with We may be very familiar with the following content because we have used it in previous MVC versions. These contents exist as properties of MvcOptions. The specific function list is as follows (I will not describe them one by one): 1.Filters 2. ModelBinders 3.ModelValidatorProviders 4.ValidationExcludeFilters 5.ValueProviderFactories Two more: MaxModelValidationErrors Set model validation to display the highest number of errors. RespectBrowserAcceptHeader When using the content agreement function of Web API, whether to comply with the definition of Accept Header. By default, when the media type is */*, the Accept header is ignored. If set to true, it is not ignored. |
<<: Interpreting ASP.NET 5 & MVC6 Series (14): View Component
>>: Interpreting ASP.NET 5 & MVC6 Series (16): Customizing View View File Search Logic
As a "future" TV, Honor Smart Screen ha...
Nowadays we live in a fast-paced era. Except for ...
With Facebook changing its name to Meta, the conc...
Every year, from the national level to the villag...
Commemorates the bicentenary of the discovery of ...
During this period, Tik Tok has become popular an...
In the hot summer, it is time to fill in the coll...
If you just take a quick look, the slightly turbi...
Wuhan high-end tea drinking is unique and very un...
Overview 1. Advertising styles and scenarios The ...
Today, Tesla launched the basic version of Model ...
Every family has a small balcony, a balcony of a ...
In recent years, China's smart TV and Android...
Many people must know about selling products on Z...
What is the fastest time you have ever taken from...