(GlobalImport global import function) In the default newly created MVC program, a new _GlobalImport.cshtml file and a _ViewStart.cshtml file are added to the Views directory. The function of this file is similar to the web.config file in the Views directory. Previously, we often set the global import namespace in this file to avoid repeating the @using xx.xx statement in each view file. The default example is as follows:
The above code indicates that the BookStore and Microsoft.Framework.OptionsModel namespaces, as well as all namespaces under the Microsoft.AspNet.Mvc.TagHelpers assembly are referenced. We have already explained the addTagHelper function in TagHelper. Note that in this example, we only referenced the BookStore namespace and did not reference the BookStore.Controllers namespace, so we cannot access the HomeController class in any view (nor can we access it as Controllers.HomeController). I hope Microsoft can improve this in the future. Get IP related information To obtain the IP address information of the user visitor, you can use dependency injection to obtain an instance of IHttpConnectionFeature, from which you can obtain the relevant information of the IP address. The example is as follows: var connection1 = Request.HttpContext.GetFeature Similarly, you can also obtain related instances through interfaces such as IHttpRequestFeature, IHttpResponseFeature, IHttpClientCertificateFeature, and IWebSocketAcceptContext, and use the features on the instance. The above interfaces are all under the namespace Microsoft.AspNet.HttpFeature. File upload MVC6 provides new improvements in file upload, as shown below:
We define the above upload form on the front-end page, and can use the new file type IFormFile in MVC6 when receiving it. The example is as follows: [HttpPost] public async Task |
<<: Interpreting ASP.NET 5 & MVC6 Series (16): Customizing View View File Search Logic
Google released a powerful tool this morning to h...
Friends who have some knowledge of Feng Shui orna...
It is the heaviest fruit in the world. Although i...
Maybe I smelled some perfume. Seeing the poor hom...
Usually, there are very few women around me who e...
There are many ways to attract new customers to y...
[[134475]] Rumors about Microsoft acquiring Black...
This is the 4825th article of Da Yi Xiao Hu Recen...
Although the latest data released by the Ministry ...
Rumors If you don’t lose weight in March, you wil...
The Olympic Games have just ended. In this Olympi...
In view of the fact that everyone had many diffic...
1. Taboos for modifying the TDK on the homepage S...
Is live streaming sales a “temporary trend” or a ...
Machine learning is a hot topic in the field of d...