ASP. NET Core project structure tutorial (4), asp. netcore

Source: Internet
Author: User

ASP. NET Core project structure tutorial (4), asp. netcore

In this chapter, we will discuss the composition of ASP. NET Core projects on the file system and how different files and directories work together.

Let's open the FirstAppDemo project created in the previous chapter.

In the Solution Explorer window, right-click the solution node and select "Open Folder in File Explorer ".

You will see two files under its root directory: FirstAppDemo. sln and global. json.

The FirstAppDemo. sln file is a solution file. Visual Studio has been using the sln extension name by default for many years. If you want to open an application in Visual Studio, you can double-click the file.

There is also a global. json file. Open this file in Visual Studio.

In the global. json file, project settings are very important. This project tells ASP. NET where to find your source code and which folders contain your project source code.

Generally, a new project contains two important folders: the "source" folder containing the source code and a "test" folder. Project compilation fails unless both your project and source code are in these two folders. If necessary, you can change these settings as needed.

There is no test folder in our current project. In the test folder, you can store your unit test projects. Double-click the "src" folder.

You can see that the FirstAppDemo web application project is now, double-click the folder.

These are application source code files. You can also see the folder structure in the Solution Explorer window.

If you add a new file to the project folder, the file is automatically added to the project. If you delete an object, it will also be deleted from the project. The project and file system are all synchronized, which is a little different from the previous Asp. NET version.

When a file is changed or a new file is added, ASP. NET Core automatically compiles your application.

Case

Let's take a look at a simple example. Open the Startup. cs file in Notepad:

The following line of code is used to respond to each HTTP request sent to the application. Here it only responds to "Hello World !"

Let's modify the above string to "Hello World! This ASP. NET Core Application ", as shown below:

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging; namespace FirstAppDemo { public class Startup {   // This method gets called by the runtime.   // Use this method to add services to the container.   // For more information on how to configure your application,   // visit http://go.microsoft.com/fwlink/?LinkID=398940   public void ConfigureServices(IServiceCollection services) {   }     // This method gets called by the runtime.   // Use this method to configure the HTTP request pipeline.   public void Configure(IApplicationBuilder app,    IHostingEnvironment env, ILoggerFactory loggerFactory) {    loggerFactory.AddConsole();       if (env.IsDevelopment()){    app.UseDeveloperExceptionPage();    }    app.Run(async (context) => {    await context.Response.WriteAsync(    "Hello World! This ASP.NET Core Application");   });  }  } }

Press Ctrl + S in the text editor to save the file, return to the web browser, and refresh the application.

Now you can see that your changes are reflected in the browser.

  • This is because ASP. NET monitors the file system and automatically compiles the application when the file changes. You do not need to explicitly recompile the application in Visual Studio.
  • In fact, you can use a different editor, such as Visual Studio Code.
  • All you need to do when using Visual Studio is to start the web server by running the debugger. You can also press Ctrl + F5 to edit the file, save the file, and refresh the browser to view the changes.
  • This is a good process for building web applications using C.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.