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 is ASP.NET Core?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you what ASP.NET Core is, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!

What is the .NET Core?

Many friends think it is ASP.NET Core when they see .NET Core. In fact, this is a misunderstanding, because .NET Core is an open source general development platform (a "platform"). Based on this open platform, we can develop ASP.NET Core applications, Windows 10 General Windows platform (UWP), Tizen and so on. Our series of tutorials are to develop ASP.NET Core applications with .NET Core. It is also maintained on GitHub by the official Microsoft team and .NET community members. It is cross-platform (supports Windows, macOS, and Linux) and can be used to generate device, cloud, and IoT applications.

The .NET Core also has the following features:

Cross-platform: can run on Windows, macOS, and Linux operating systems.

Consistent across architectures: running code with the same behavior on multiple architectures, including x64, x86, and ARM.

Command line tools: includes easy-to-use command line tools for local development and continuous integration scenarios.

Deployment flexibility: can be included in the scope of applications or installed parallel users or computers. It can be used with Docker container.

Compatibility: .NET Core is compatible with .NET Framework, Xamarin, and Mono through the .NET Standard.

Open source:. NET Core is an open source platform using MIT and Apache 2 licenses. The .NET Core is a .NET Foundation project.

Supported by Microsoft:. NET Core relies on a strong Microsoft team for maintenance.

What is ASP.NET Core?

ASP.NET Core is a web framework created by Microsoft to build web applications, API, and micro services. It uses common patterns such as MVC (Model-View-Controller), dependency injection, and a request processing pipeline made up of middleware. It is based on the Apache 2.0 license open source, that is, the source code is freely available, and community members are welcome to contribute in the form of bug fixes and new feature submissions.

ASP.NET Core runs on Microsoft's. Net runtime library, similar to Java's virtual machine (JVM) or Ruby's interpreter. There are several languages that can be used to write ASP.NET Core programs. C # is the most common choice, and of course most of me use C # for development. You can build and run ASP.NET Core applications on Windows, Mac, and Linux.

Why use ASP.NET Core to develop applications

There are already a lot of web framework options available: Node/Express, Spring, Ruby on Rails, Django, Laravel, and so on. What are the merits of ASP.NET Core? Why use ASP.NET Core to develop applications?

The speed ASP.NET Core is very fast. Because .NET Core is compiled and runs much faster than interpretive languages, such as JavaScript or Ruby, ASP.NET Core has also been specifically optimized for multithreaded and asynchronous tasks. It is normal to execute 5-10 times faster than code written in Node.js.

Ecological ASP.NET Core may be fledgling, but .NET has been tested. There are thousands of software packages on NuGet (.NET 's package management system, like npm, Ruby gems, or Maven). There are ready-made packages for JSON deserialization, database connections, PDF generation, or almost any requirement you can think of.

Security Microsoft's founding team pays great attention to security, and ASP.NET Core is secure from the foundation. It already automatically handles cleansing input data and cross-domain forgery requests (CSRF), so you don't have to worry about it. You also enjoy the advantage of the static type checking of the .NET compiler, which is like a vigilant and obsessive-compulsive reviewer. In this way, those unconscious errors are inevitable when using a variable or some data.

Cross-platform can run on Windows, Mac, or Linux with .NET runtime libraries installed.

The open source .NET Core is an open source (MIT license), which was provided to the .NET Foundation by Microsoft in 2014. It is now one of the most active .NET Foundation projects. It can be freely adopted by individuals and businesses, including for personal, academic or commercial purposes. At the same time, open source also means that when you have a problem, you can read its source code to get the solution to the problem, and you can also mention Issue on Gayhub.

Millions of developers have used (and will continue to use) ASP.NET 4.x to create Web applications. ASP.NET Core is a redesigned ASP.NET 4.x that has changed the architecture to form a more streamlined modular framework.

ASP.NET Core also has the following advantages:

Generate a unified scenario of Web UI and Web API.

Build for testability.

Razor Pages can make page-based coding simpler and more efficient.

Ability to develop and run on Windows, macOS and Linux.

Open source and community-centric.

Integrate the new client framework and development workflow.

Environment-based cloud-ready configuration system.

Built-in dependency injection.

Lightweight, high-performance, modular HTTP request pipeline.

Can be hosted on IIS, Nginx, Apache, Docker or self-hosted in your own process.

Based on the .NET Core runtime, you can use parallel application versioning.

NET Core environment building

Before we can proceed with writing the ASP.NET Core code, we need to install the runtime environment for the .NET Core. In this part, we will build the environment of .NET Core step by step.

1. First of all, you can Google to search the .NET Core, and if that's right, the first one is the official download address of Microsoft. Of course, you can click here to download (currently, the latest version of sdk is v2.1.500, the latest version of runtime is v2.1.6) to download SDK.

two。 Double-click the sdk you downloaded and install it step by step. Microsoft's software installation is so easy that you will find me verbose if I talk about it in more detail. So, here I will only post a picture of the successful installation.

3. Next, hold down the Shift+ right mouse button and select "Open Powershell window here" or "Open Command Line window here". Then type dotnet-- info to check the information about the .NET Core that we have installed, the current running environment, the version information that has been installed in the past, I have a lot of versions, because I have been using it for a long time. If you install it for the first time, there may be only one. The interface of the second picture below shows that our. Net core development environment is ready! Let's roll up our sleeves and get to work.

Quickly create an ASP.NET Core project and conduct practical drills

Here, in order to take care of more friends, I do not use the CLI command line to create ASP.NET Core projects, or to use VS2017 properly! What vs2017 needs an activation code? Then you can use the community version! For the community version, learning is enough! There's a lot of nonsense, let's get started!

1. The first step must be to open your VS2017, then click "File"-"New"-"Project" in the upper left corner (or if you find it troublesome, you can use the shortcut key Ctrl+Shift+N), open the following dialog box to create a new project, then select as shown in the figure and click OK (what? You didn't build it? Then I think you are insulting me.

two。 Haha, after clicking OK above, the next dialog box will pop up, which will let you choose whether the target framework is .NET Core or .NET Framework; whether to create an empty solution or a web project with templates! As for their own differences, interested friends can create each and then compare their differences! Here we select MVC's web application as shown in the following figure:

3. After the creation is successful, you can see the following structure, the standard MVC structure, but it is different from the MVC of. Net framework era. Wwwroot: the static file directory of the website (why can it be loaded here? You can think about it first)

Appsettings.json: configuration files, such as database connection strings, and so on.

Program.cs: program entry file (with a Main method)

Startup.cs startup configuration file

Dependencies: manage the installation, configuration, and upgrade of third-party components that the project depends on

Controller: controller

Models: solid

Views: view

Due to the limited space, there is not too much explanation.

4. Press F5 on the keyboard or click the run button as shown below to see the effect.

5. If nothing happens, you will see the interface shown in the following figure.

6. See, it's as simple as that. We just run a MVC site for ASP.NET Core. Is it over when you get here? You think too much about it, because I want you to order more things. So this sixth rule is used to talk nonsense, and then as a division.

7.Models: right-click on the Models folder to create two new classes: a Content class and a ContentViewModel class with the following code (I won't teach you how to create a class here, but if I tell you, it's an insult to your intelligence):

Namespace Sample01.Models {/ 2018.11.19 / / Zhu Lei / / content entity / public class Content {/ Primary key / public int Id {get; set;} / public string title {get; set;} / content / public string content {get; set } / status 1 normal 0 Delete / public int status {get; set;} / public DateTime add_time {get; set;} / modify time / public DateTime modify_time {get; set } namespace Sample01.Models {/ 2018.11.19 / / Zhu Lei / Content View Mode / public class ContentViewModel {/ content list / public List Contents {get; set;}

8.Controller: once the model is built, let's create a new controller, and then create some simulated data. The code is as follows:

Namespace Sample01.Controllers {/ 2018.11.19 / / Zhu Lei / Content Controller / public class ContentController: Controller {/ public IActionResult Index () {var contents = new List (); for (int I = 1; I < 11) Contents.Add (title of new Content {Id=i,title=$ "{I}", content= $"content of {I}, status=1, add_time=DateTime.Now.AddDays (- I)});} return View (new ContentViewModel {Contents=contents});}

9.Views: now that the model and controller are built, let's build a view to show the data we created. We can create this view in many ways. Here we introduce you to a silly one. Place the mouse inside the Index curly braces, and then right-click to create the view. You can create the view file as follows, located in the / Views/Content/Index.cshtml file:

10. Let's modify the View slightly as follows:

@ model ContentViewModel@using Humanizer;@ {ViewData ["Title"] = "content list";} @ ViewData ["Title"] sequence number title content addition time @ foreach (var item in Model.Contents) {@ item.Id @ item.title @ item.content @ item.add_time.Humanize ()}

11. Then modify the layout file, which stores the "base" HTML of all views in the layout file of Views/Shared/_Layout.cshtml. This includes the navigation bar, which is displayed at the top of each page. In order to add a new entry to the navigation bar, we need to add our Content column to this file, as follows:

Content

twelve。 At this point, the code is almost complete, press your F5 key, and then navigate to Content to see the effect:

The above is all the content of this article "what is ASP.NET Core?" thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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