ASP.NET Core - Bắt đầu tạo ứng dụng

Bắt đầu tạo ứng dụng trong ASP.NET Core

Tao một project

Để bắt đầu tạo một ứng dụng ASP.NET Core. 

To start, you'll create an ASP.NET Core web application project. The project type comes with all template files to create a web app, before you've even added anything!

  1. Mở Visual Studio.

  2. Trên thanh start window, chọn Create a new project.

    View the 'Create a new project' window

  3. Trong cửa sổ Create a new project , nhập vào ASP.NET  trong họp tìm kiếm. Tiếp theo, chọn C# , và sau đó chọn Windows.

    Sau khi apply ngôn ngữ và lọc platform, chọn template ASP.NET Core Web Application, và kế tiếp chọn Next.

    Choose the C# template for the ASP.NET Core Web Application

    Nếu bạn không thấy template ASP.NET Core Web Application , bạn có thể cài đặt template từ  Create a new project . trong Not finding what you're looking for? , chọn Install more tools and features .

    The 'Install more tools and features' link from the 'Not finding what you're looking for' message in the 'Create new project' window

    Sau đó, trong Visual Studio Installer, chọn ASP.NET and web development .

    ASP.NET Core Web Application workload in the Visual Studio Installer

    Sau đó, chọn nút Modify trong Visual Studio Installer. Lưu công việc hành. Kế tiếp, chọn Continue để cài đặt. Sau đó, trở về bước 2 trong  "Create a project" .

  4. Trong cửa sổ Configure your new project , Nhập tên HelloWorld  trong Project name . Sau đó, chọn Create.

    in the 'Configure your new project' window, name your project 'HelloWorld'

  5. Trong cử sổ Create a new ASP.NET Core Web Application , Xác nhận ASP.NET Core 2.1. Sau đó, chọn Web Application, chứa ví dụ Razor Pages. Kế tiếp, chọnCreate.

    The 'Create a new ASP.NET Core Web Application' window

    Tạo và chạy app

  1. Trong Solution Explorer, Mở rộng thư mục Pages, sau đó, chọn About.cshtml.

    Choose the About.cshtml file from the Solution Explorer

    Tập tin này trả về trang About khi xem trong trình duyệt web.
    The About page in the web app

  2. Trong editor, bạn sẽ thấy code HTML "additional information" trong trang About.

    The HTML code for the additional information area in the Visual Studio editor

  3. Thay đổi nội dung "additional information" thành "Hello World!".

    Change the default The HTML code for the additional information area in the Visual Studio editor

  4. Trong Solution Explorer, Mở rộng About.cshtml, sau đó, chọn About.cshtml.cs.

    Choose the About.cshtml file from the Solution Explorer

    Bên trong code behind  "application description" .

    The C# code for the application description area in the Visual Studio editor

  5. Thay đổi nội dung"application description" thành "What's my message?".

    Change the default message text for the application description area in the Visual Studio editor

  6. Chọn IIS Express hoặc Ctrl+F5 để chạy app.

    Select the IIS Express button in Visual Studio

    Chú ý: Nếu bạn thấy lỗi Unable to connect to web server 'IIS Express', hoặc thông báo lỗi đề cập đến chứng thực SSL, đóng Visual Studio. Tiếp theo, mở Visual Studio bằng cách sử dụng tùy chọn Run as Administrator từ menu. Sau đó, chạy lại ứng dụng.
  7. Kết quả trong trình duyệt web.
    View the updated About page that includes the changes you made

  8. Đóng trình duyệt.

Xem demo sau để kiểm tra công việc bạn đã hoàn thành trong phần trước.

View the animated .gif file that shows how to create and run a simple C# ASP.NET Core web app in Visual Studio