📜  dotnet core webapp - C# (1)

📅  最后修改于: 2023-12-03 15:14:47.551000             🧑  作者: Mango

Introduction to .NET Core WebApp in C#

What is .NET Core?

.NET Core is a free and open-source, cross-platform framework used for building modern, cloud-based, internet-connected applications. It's a major version of .NET framework that is modular, lightweight, and optimized for performance.

What is a WebApp in C#?

A WebApp is simply a web application that is written in C# programming language. It can be hosted on any web server, allowing users to access it through a web browser. In a WebApp, you can create web pages, handle user input, and interact with databases, among other things.

Getting Started with .NET Core WebApp

To get started with .NET Core WebApp, you need to have the following tools installed:

  • .NET Core SDK
  • Visual Studio Code or any other text editor
Creating a new project

To create a new .NET Core WebApp project, open a command prompt, and run the following command:

dotnet new webapp -n MyWebApp
  • dotnet new webapp: This command creates a new .NET Core WebApp project.
  • -n MyWebApp: This command sets the name of the project to "MyWebApp".
Running the project

To run the project, navigate to the project folder, and run the following command:

dotnet run

This command builds and runs the project. Open your web browser and navigate to http://localhost:5000 to view your WebApp.

Important files in a .NET Core WebApp

When you create a new .NET Core WebApp project, there are some files and folders that are generated automatically. Here's a brief description of some of the important files and folders:

  • Program.cs: This file contains the Main method of the application. It creates and configures the WebHost and runs the application.
  • Startup.cs: This file contains the Startup class, which configures the application services and middleware.
  • wwwroot: This folder contains the static files of the application, such as CSS, JavaScript, and images.
  • Controllers: This folder contains the C# classes that handle incoming HTTP requests and generate HTTP responses.
  • Views: This folder contains the HTML templates that generate the dynamic content of the application.
Conclusion

.NET Core WebApp in C# is a powerful tool for building modern, cloud-based, internet-connected applications. With .NET Core, you can create high-performance, cross-platform web applications that run on Windows, macOS, and Linux.