目录
1. Install the ASP.NET Core Hosting Bundle
2. Publish the Application
Using Visual Studio:
Using CLI:
3. Copy Files to the Server
4. Create an IIS Site or Application
Option A: New Site
Option B: As Application under Default Site
5. Configure web.config (Optional but Important)
6. Set Up Application Pool
7. Test the Deployment
Common Issues & Tips
首页 专题 IIS 如何将ASP.NET核心应用程序部署到IIS?

如何将ASP.NET核心应用程序部署到IIS?

Aug 26, 2025 am 05:35 AM

安装 ASP.NET Core Hosting Bundle 以确保服务器支持 ASP.NET Core 应用运行,包含 .NET 运行时和 IIS 模块,并通过命令 net stop was /y 和 net start w3svc 重启 IIS;2. 使用 Visual Studio 或 CLI(dotnet publish -c Release -o C:\publish)发布应用,推荐使用框架依赖部署;3. 将发布文件复制到服务器目录(如 C:\inetpub\wwwroot\MyApp),并确保 IIS_IUSRS 具有读取和执行权限;4. 在 IIS 中创建新网站或作为应用程序添加到默认网站,配置站点名称、物理路径和绑定;5. 确保 web.config 文件正确配置 handlers 和 aspNetCore 模块,设置 processPath="dotnet"、arguments=".\YourApp.dll",并根据需要选择 hostingModel="inprocess" 或 "outofprocess",若启用 stdoutLogEnabled 则需创建 logs 目录;6. 配置应用程序池,将 .NET CLR 版本设为“无托管代码”,托管管道模式设为“集成”;7. 浏览网站验证部署,若失败则检查事件查看器、启用 stdout 日志、确认 DLL 名称和 Hosting Bundle 安装状态,常见问题包括 502.5 错误(由运行时缺失或参数错误引起)和无效可执行文件错误,建议使用 inprocess 模式提升性能,避免不必要的自包含发布,使用 appsettings.Production.json 管理生产环境配置,最终确保路径、权限和配置一致以完成部署。

How to deploy an ASP.NET Core application to IIS?

Deploying an ASP.NET Core application to IIS involves several steps because ASP.NET Core apps run as standalone processes and are reverse-proxied through IIS using the ASP.NET Core Module. Here’s how to do it properly.

How to deploy an ASP.NET Core application to IIS?

1. Install the ASP.NET Core Hosting Bundle

Before deploying, ensure the target Windows server has the ASP.NET Core Hosting Bundle installed. This bundle includes:

  • The .NET Runtime
  • The .NET Core Runtime
  • The ASP.NET Core Module for IIS

? Download it from the official Microsoft site: //m.sbmmt.com/link/a4cd9bc071c923daab48132b0bb2e4f3 (look under "Hosting Bundle").

How to deploy an ASP.NET Core application to IIS?

After installing, restart IIS by running in Command Prompt (as admin):

net stop was /y
net start w3svc

This ensures the ASP.NET Core Module is properly loaded.

How to deploy an ASP.NET Core application to IIS?

2. Publish the Application

From your development machine, publish the app for deployment:

Using Visual Studio:

  • Right-click the project → Publish
  • Choose Folder or a custom profile
  • Set target framework (e.g., net8.0)
  • Set deployment mode: Framework-dependent (recommended unless you need self-contained)
  • Click Publish

Using CLI:

dotnet publish -c Release -o C:\publish

This creates a self-contained or framework-dependent output in the specified folder.


3. Copy Files to the Server

Copy the published files (from the publish folder) to a directory on the IIS server, e.g.:

C:\inetpub\wwwroot\MyApp

Ensure IIS has read and execute permissions on this folder. The IIS_IUSRS group should have access.


4. Create an IIS Site or Application

Option A: New Site

  • Open IIS Manager
  • Right-click SitesAdd Website
  • Set:
    • Site name: MyApp
    • Physical path: C:\inetpub\wwwroot\MyApp
    • Binding: e.g., port 80, hostname if needed
  • Ensure Start Automatically is checked

Option B: As Application under Default Site

  • Expand Default Web Site
  • Right-click → Add Application
  • Alias: MyApp
  • Physical path: same as above

5. Configure web.config (Optional but Important)

The web.config file should be included in the published output. If missing, create one:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" 
                  arguments=".\YourApp.dll" 
                  stdoutLogEnabled="false" 
                  stdoutLogFile=".\logs\stdout" 
                  hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

? Use hostingModel="inprocess" for better performance (runs inside IIS worker process), or outofprocess to isolate the .NET Core process.

? Make sure the logs folder exists if stdoutLogEnabled="true" — useful for debugging startup issues.


6. Set Up Application Pool

Ensure the application pool is configured correctly:

  • Go to Application Pools
  • Find the pool used by your site
  • Set .NET CLR Version to No Managed Code
  • Set Managed Pipeline Mode to Integrated

ASP.NET Core doesn’t use the legacy ASP.NET pipeline, so "No Managed Code" is correct.


7. Test the Deployment

Browse to your site:

http://yoursite.com

If you see a 500 error or nothing:

  • Check Windows Event Viewer → Windows Logs → Application for errors
  • Enable stdoutLogEnabled="true" and check the logs folder
  • Verify the app DLL name in web.config matches your published .dll
  • Confirm the Hosting Bundle is installed and IIS restarted

Common Issues & Tips

  • "The specified executable is not a valid application": Usually means the Hosting Bundle isn’t installed or the app isn’t published correctly.
  • 502.5 Process Failure: Often due to missing runtime or incorrect arguments in web.config.
  • ✅ Use inprocess hosting for better performance unless you need isolation.
  • ✅ Avoid publishing with self-contained unless necessary — it increases size.
  • ✅ Use appsettings.Production.json to manage environment-specific settings.

That’s it. Once the Hosting Bundle is in place and the app is published correctly, IIS will proxy requests to your ASP.NET Core app via the ASP.NET Core Module. Just make sure file permissions, paths, and configuration align.

以上是如何将ASP.NET核心应用程序部署到IIS?的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Stock Market GPT

Stock Market GPT

人工智能驱动投资研究,做出更明智的决策

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

如何在64位IIS上运行32位应用程序? 如何在64位IIS上运行32位应用程序? Sep 16, 2025 am 05:53 AM

启用32位应用支持是关键步骤,需在IIS管理器中找到对应应用池,将“启用32位应用程序”设置为True;2.修改后回收应用池使配置生效;3.确保32位DLL或COM组件通过SysWOW64目录的regsvr32注册,并检查应用池身份权限。

如何调试在IIS中运行的应用程序? 如何调试在IIS中运行的应用程序? Sep 21, 2025 am 12:45 AM

Identifythecorrectw3wp.exeprocessbyrunningiisappinCommandPrompttomatchyourapp’sapplicationpoolwithitsPID.2.InVisualStudio,attachthedebuggertotheidentifiedw3wp.exeprocess,selectingtheappropriatedebuggertype(ManagedorCoreCLR).3.Ensuredebug="true&q

如何使用LogParser对IIS性能问题进行故障排除? 如何使用LogParser对IIS性能问题进行故障排除? Sep 21, 2025 am 02:48 AM

UseLogParsertoidentifyslow-runningrequestsbyqueryingthetime-takenfieldandsortingindescendingordertofindthetop10slowestrequests,whichhelpsdetectinefficientendpoints;2.Analyzehigh-trafficendpointsbygroupingURLsandcountinghitstouncoverresourcesunderheav

如何使用PowerShell管理IIS? 如何使用PowerShell管理IIS? Sep 18, 2025 am 06:21 AM

TomanageIISwithPowerShell,firstinstallandimporttheWebAdministrationmodule,thenusetheIIS:driveandcmdletstocreatewebsites,configureapplicationpools,setbindings,andassignSSLcertificatesforautomated,repeatableadministration.

如何禁用IIS记录以获取特定网站? 如何禁用IIS记录以获取特定网站? Sep 16, 2025 am 06:54 AM

要关闭IIS上某个特定网站的日志记录,首先在IIS管理器中找到目标网站并进入“日志记录”设置,1.将“日志计划”设为“无”,2.取消勾选“启用日志记录”,3.点击应用保存更改,操作仅影响当前网站;注意旧日志不会自动删除,需手动清理,同时确认日志路径是否共享、权限是否正常以及监控工具是否依赖日志,避免后续问题。

如何在IIS上配置PHP? 如何在IIS上配置PHP? Sep 20, 2025 am 07:03 AM

安装PHP并配置php.ini,启用必要扩展;2.在IIS中启用CGI功能;3.通过IIS管理器将PHP注册为FastCGI应用,添加*.php映射;4.创建info.php测试文件验证配置,确保权限和路径正确,必要时重启IIS。

如何解决IIS中的不良请求错误(400)? 如何解决IIS中的不良请求错误(400)? Sep 17, 2025 am 07:06 AM

检查请求大小和URL限制,通过调整web.config中的maxAllowedContentLength、maxRequestLength、maxUrl和maxQueryString来解决超限问题;2.检查无效的请求头或编码,使用Fiddler或失败请求跟踪识别并修复格式错误的头部;3.排查HTTPS/SSL问题,确保客户端使用HTTPS、正确配置SNI且绑定匹配;4.确保请求体格式正确且Content-Type匹配,避免模型绑定错误;5.对URL中的特殊字符进行编码,谨慎使用allowDoub

安装IIS后如何修复'服务器应用程序错误”? 安装IIS后如何修复'服务器应用程序错误”? Sep 15, 2025 am 02:41 AM

启用IIS中的ASP.NET功能;2.以管理员身份运行aspnet_regiis-i注册ASP.NET;3.在应用池中设置正确的.NET版本和集成管道模式;4.为IIS_IUSRS和应用池身份授予网站文件夹读取与执行权限;5.可选启用失败请求跟踪并检查日志;6.检查web.config文件错误和事件查看器中的应用错误;通过依次执行上述步骤可解决IIS安装后出现的“服务器应用程序错误”,确保ASP.NET正确注册并配置应用池,最终使网站正常运行。

See all articles