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
According to news from Songshan Lake Science City...
If someone asked you, if you don’t want to stay i...
Google started developing the Android system as e...
[51CTO.com original article] A reader complained ...
Three-toed sloth Image credit: Unslpash Sloths ar...
Tianzhou spacecraft publicly "collects items...
I have been working on TikTok for more than a yea...
Recently, the topic #Chinese light meals are more...
Recently I saw a written test question that requi...
On September 19, Li Xiang posted on Weibo about t...
Unattended project: automated traffic transaction...
This article will focus on interpreting and analy...
[Daiyu Finance] Pantaoyuan Swallow Returns Strate...
As the saying goes, "Food is the most import...
Qingxu Grain and Oil Mini Program Production Pric...