Bagikan melalui


Menerbitkan aplikasi ASP.NET Core ke IIS

Tutorial ini menunjukkan cara menghosting aplikasi ASP.NET Core di server IIS.

Tutorial ini mencakup subjek berikut:

  • Instal .NET Core Hosting Bundle di Windows Server.
  • Buat situs IIS di Manajer IIS.
  • Menyebarkan aplikasi ASP.NET Core.

Prerequisites

  • .NET Core SDK diinstal pada komputer pengembangan.
  • Windows Server dikonfigurasi dengan peran server Server Web (IIS). If your server isn't configured to host websites with IIS, follow the guidance in the IIS configuration section of the Host ASP.NET Core on Windows with IIS article and then return to this tutorial.

Warning

Konfigurasi IIS dan keamanan situs web melibatkan konsep yang tidak tercakup dalam tutorial ini. Lihat panduan IIS dalam dokumentasi Microsoft IIS dan artikel ASP.NET Core tentang hosting dengan IIS sebelum menghosting aplikasi produksi di IIS.

Skenario penting untuk hosting IIS yang tidak tercakup dalam tutorial ini meliputi:

Memasang .NET Core Hosting Bundle

Instal .NET Core Hosting Bundle di server IIS. Bundel memasang .NET Core Runtime, .NET Core Library, dan ASP.NET Core Module. Modul ini memungkinkan aplikasi ASP.NET Core berjalan di belakang IIS.

Unduh alat penginstal menggunakan tautan berikut:

Alat penginstal .NET Core Hosting Bundle saat ini (unduh langsung)

  1. Jalankan alat penginstal di server IIS.

  2. Mulai ulang server atau jalankan net stop was /y diikuti dengan net start w3svc dalam shell perintah.

Membuat situs IIS

  1. Di server IIS, buat folder untuk berisi folder dan file aplikasi yang diterbitkan. Pada langkah berikut, jalur folder disediakan ke IIS sebagai jalur fisik ke aplikasi. Untuk informasi lebih lanjut tentang folder penyebaran dan tata letak file aplikasi, lihat Struktur direktori ASP.NET Core.

  2. In IIS Manager, open the server's node in the Connections panel. Right-click the Sites folder. Select Add Website from the contextual menu.

  3. Provide a Site name and set the Physical path to the app's deployment folder that you created. Provide the Binding configuration and create the website by selecting OK.

    Warning

    Top-level wildcard bindings (http://*:80/ and http://+:80) should not be used. Pengikatan wildcard tingkat atas dapat mengekspos aplikasi Anda terhadap kerentanan keamanan. Ini berlaku untuk wildcard kuat dan lemah. Gunakan nama host eksplisit alih-alih wildcard. Pengikatan wildcard subdomain (misalnya, *.mysub.com) tidak memiliki risiko keamanan ini jika Anda mengontrol seluruh domain induk (alih-alih *.com, yang rentan). Lihat RFC 9110: Semantik HTTP (Bagian 7.2. Host dan :authority) untuk informasi lebih lanjut.

  4. Pastikan identitas dari model proses memiliki izin yang tepat.

    If the default identity of the app pool (Process Model>Identity) is changed from ApplicationPoolIdentity to another identity, verify that the new identity has the required permissions to access the app's folder, database, and other required resources. Misalnya, kelompok aplikasi memerlukan akses baca dan tulis ke folder tempat aplikasi membaca dan menulis file.

Membuat aplikasi ASP.NET Core

Buat semua jenis aplikasi berbasis server ASP.NET Core.

Note

Tutorial ini didasarkan pada hosting aplikasi ASP.NET Core sisi server dengan IIS, termasuk Blazor Web App. Untuk panduan tentang menghosting dan menyebarkan aplikasi mandiri Blazor WebAssembly dengan IIS, lihat Menghosting dan menyebarkan ASP.NET Core Blazor WebAssembly dengan IIS.

Menerbitkan dan menyebarkan aplikasi

Menerbitkan aplikasi berarti menghasilkan aplikasi yang dikompilasi yang dapat dihosting oleh server. Menyebarkan aplikasi berarti memindahkan aplikasi yang diterbitkan ke sistem hosting. Langkah penerbitan ditangani oleh .NET Core SDK, sementara langkah penyebaran dapat ditangani oleh berbagai pendekatan. This tutorial adopts the folder deployment approach, where:

  • Aplikasi diterbitkan ke folder.
  • The folder's contents are moved to the IIS site's folder (the Physical path to the site in IIS Manager).
  1. Right-click on the project in Solution Explorer and select Publish.
  2. Dalam dialog Pilih target penerbitan, pilih opsi Terbitkan folder.
  3. Atur jalur Folder atau Berbagi File.
    • Jika Anda membuat folder untuk situs IIS yang tersedia di komputer pengembangan sebagai berbagi jaringan, berikan jalur ke berbagi. Pengguna saat ini harus memiliki akses tulis untuk menerbitkan ke berbagi.
    • If you're unable to deploy directly to the IIS site folder on the IIS server, publish to a folder on removable media and physically move the published app to the IIS site folder on the server, which is the site's Physical path in IIS Manager. Move the contents of the bin/Release/{TARGET FRAMEWORK}/publish folder to the IIS site folder on the server, which is the site's Physical path in IIS Manager.
  4. Select the Publish button.

Telusuri situs web

Aplikasi ini dapat diakses di browser setelah menerima permintaan pertama. Buat permintaan ke aplikasi di pengikatan titik akhir yang Anda tetapkan di Manajer IIS untuk situs tersebut.

Next steps

Dalam tutorial ini, Anda mempelajari cara:

  • Instal .NET Core Hosting Bundle di Windows Server.
  • Buat situs IIS di Manajer IIS.
  • Menyebarkan aplikasi ASP.NET Core.

Untuk mempelajari selengkapnya tentang menghosting aplikasi ASP.NET Core di IIS, lihat artikel Gambaran Umum IIS:

Additional resources

Artikel dalam kumpulan dokumentasi ASP.NET Core

Artikel yang berkaitan dengan penyebaran aplikasi ASP.NET Core

Artikel tentang konfigurasi HTTPS IIS

Artikel tentang IIS dan Windows Server

Sumber daya penyebaran untuk administrator IIS