Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the new features in ASP.NET5 MVC6

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the new features in ASP.NET5 MVC6". In daily operation, I believe many people have doubts about what the new features in ASP.NET5 MVC6 are. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the new features in ASP.NET5 MVC6?" Next, please follow the editor to study!

(GlobalImport global import function)

By default, in the newly created MVC program, a new _ GlobalImport.cshtml file and _ ViewStart.cshtml level have been added in the Views directory. The function of this file is similar to the web.config file in the previous Views directory. We often set the global import namespace in this file to avoid repeated @ using xx.xx statements in each view file.

The default examples are as follows:

Using BookStore @ using Microsoft.Framework.OptionsModel @ addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"

The above code represents a reference to the BookStore and Microsoft.Framework.OptionsModel namespaces, as well as all namespaces under the Microsoft.AspNet.Mvc.TagHelpers assembly.

With regard to addTagHelper functionality, we have already explained the note in TagHelper. In this case, we only refer to the BookStore namespace, not the BookStore.Controllers namespace, so we cannot access the HomeController class in any view (nor can we access it in the form of Controllers.HomeController). We hope Microsoft can improve it in the future.

Get IP related information

To obtain information about the IP address of a user visitor, you can use dependency injection to obtain an instance of IHttpConnectionFeature, from which you can obtain information about the IP address, as shown below:

Var connection1 = Request.HttpContext.GetFeature (); var connection2 = Context.GetFeature (); 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 use the features on the instance by obtaining related instances through IHttpRequestFeature, IHttpResponseFeature, IHttpClientCertificateFeature, IWebSocketAcceptContext and other interfaces, all of which are under the namespace Microsoft.AspNet.HttpFeature.

File upload

MVC6 provides new and improved processing for file upload, such as:

We define the above upload form on the front-end page, and we can use the new file type IFormFile in MVC6 when receiving. An example is as follows:

[HttpPost] public async TaskIndex (IListfiles) {foreach (var file in files) {var fileName = ContentDispositionHeaderValue .Parse (file.ContentDisposition) .filename .trim ('"') / / the string returned by the beta3 version of bug,FileName contains double quotation marks, such as "fileName.ext" if (fileName.EndsWith (".txt")) / / only save the txt file {var filePath = _ hostingEnvironment.ApplicationBasePath + "\\ wwwroot\\" + fileName; await file.SaveAsAsync (filePath);}} return RedirectToAction ("Index") / / PRG at this point, the study of "what are the new features in ASP.NET5 MVC6" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report