(Globalimport global Import feature)
By default, the newly created MVC program, in the Views directory, adds a new _GlobalImport.cshtml file and a _ViewStart.cshtml peer, The function of this file is similar to the Web.config file in the previous views directory, where we often set the global import namespace in the file to avoid reusing statements in each view file @using xx.xx .
The default example is as follows:
@using Bookstore
@using Microsoft.Framework.OptionsModel
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers "
The above code represents, references BookStore and Microsoft.Framework.OptionsModel namespaces, and Microsoft.AspNet.Mvc.TagHelpers all namespaces under the assembly.
As for the Addtaghelper function, we've already explained it in Taghelper.
Note that in this case, we only refer to BookStore namespaces and do not reference BookStore.Controllers namespaces, so we cannot access the class in any view (nor can we HomeController access it in Controllers.HomeController the form of it) and hope that Microsoft can improve it later.
Get IP-related information
To obtain information about the IP address of a user visitor, you can use dependency injection to obtain IHttpConnectionFeature an instance from which you can obtain information about the IP address, as follows:
var connection1 = request.httpcontext.getfeature<ihttpconnectionfeature> ();
var Connection2 = context.getfeature<ihttpconnectionfeature> ();
var isLocal = Connection1. IsLocal; Whether local IP
var localipaddress = Connection1. localipaddress; Local IP address
var localport = Connection1. LocalPort; Local IP Port
var remoteipaddress = Connection1. remoteipaddress; Remote IP address
var remoteport = Connection1. RemotePort; Local IP Port
Similarly, you can IHttpRequestFeature get the relevant instance through,,, and so on, using the attributes on that instance, all of which are under the IHttpResponseFeature IHttpClientCertificateFeature IWebSocketAcceptContext namespace Microsoft.AspNet.HttpFeature .
File Upload
MVC6 in the file upload aspect, has given the new improvement processing, for example as follows:
<form method= "POST" enctype= "Multipart/form-data" > <input "Files" type= "Files" name= "
file" >
<input type= "Submit" value= "Submit"/>
</form>
We define the above upload form in the front-end page, and receive the new file types in the MVC6 that can be used in the IFormFile following example:
[HttpPost]
Public async task<iactionresult> Index (ilist<iformfile> files)
{
foreach (var file in files)
{
var fileName = Contentdispositionheadervalue
. Parse (file. contentdisposition)
. FileName
. Trim (' "');//BETA3 version of Bug,filename returns a string that contains double quotes, such as" filename.ext "
if (filename.endswith (" TXT "))//Save TXT file
only {
var filePath = _hostingenvironment.applicationbasepath + "\\wwwroot\\" + fileName;
await file. Saveasasync (FilePath);
}
Return redirecttoaction ("Index");//PRG
}