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

Example Analysis of Project structure in asp.net core

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you the example analysis of the project structure in asp.net core, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Asp.Net Core- project structure

We will discuss how ASP.NET Core projects are organized on the file system and how different files and directories work together.

Let's open the FirstAppDemo project we 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 in its root directory: FirstAppDemo.sln and global.json.

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

There is also a global.json file. Let's open this file in Visual Studio.

In the global.json file, the settings of the project are very important. This project setup 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. Unless your project and source code are in these two folders, the project will fail to compile. If necessary, you can change these settings according to your needs.

We do not have a test folder in our current project. In the test folder, you can store your unit test projects. Let's double-click the "src" folder.

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

These are the source code files for the application, and you can also see this 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 a file, it will also be deleted from the project. The project keeps everything in sync with the file system, which is a little different from previous versions of Asp.NET.

ASP.NET Core also automatically compiles your application when the file changes or a new file is about to be added.

Case

Let's look at a simple example of opening the Startup.cs file in notepad:

The following line of code responds to every HTTP request made to the application, where it only responds to "Hello World!"

Let's change the string in the screenshot above 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, then go back to the web browser and refresh the application.

You can now 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, like Visual Studio Code, and so on.

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, you can edit the file, save the file, refresh the browser to see the changes.

This is a good process for building web applications using C #.

The above is all the content of the article "sample Analysis of Project structure in 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