You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MVC Azure Pipeline部署异常:IISWebAppManagementOnMachineGroup失效

问题描述

通过Azure Pipelines部署.NET Framework MVC应用至VM,使用以下任务代码:

- task: IISWebAppManagementOnMachineGroup@0
  inputs:            
    IISDeploymentType: 'IISWebsite'
    ActionIISWebsite: 'CreateOrUpdateWebsite'
    WebsiteName: 'MySite'
    WebsitePhysicalPath: 'D:/MySite/WebUi'
    WebsitePhysicalPathAuth: 'WebsiteUserPassThrough'
    CreateOrUpdateAppPoolForWebsite: true
    AppPoolNameForWebsite: 'DefaultAppPool'
    DotNetVersionForWebsite: 'No Managed Code'
    PipeLineModeForWebsite: 'Integrated'
    AppPoolIdentityForWebsite: 'ApplicationPoolIdentity'
    AddBinding: true
    Bindings: |
        {
            bindings:[
                {
                    "protocol":"http",
                    "ipAddress":"",
                    "hostname":"",
                    "port":"802",
                    "sslThumbprint":"",
                    "sniFlag":false
                }
            ]
        }
- task: IISWebAppDeploymentOnMachineGroup@0
  inputs:
    WebSiteName: 'MySite'
    Package: '$(Pipeline.Workspace)/drop/WebUi/WebUi.zip'

部署后IIS中已创建MySite站点,但访问http://*:802时出现IIS默认404错误:

Detailed Error Information:
Module     IIS Web Core
Notification       MapRequestHandler
Handler    StaticFile
Error Code     0x80070002
Requested URL      http://localhost:802/
Physical Path      D:/MySite/WebUi
Logon Method       Anonymous
Logon User     Anonymous

将应用池从「无托管代码」切换至v4.0后,变为浏览器标准404错误。站点物理路径正确,包含bin、Content、global.asax、web.config等文件。

已完成检查:

  • VM上的ASP.NET版本及Windows功能
  • WebUi文件夹的IIS权限
  • 修改DotNetVersionForWebsite为v4.0并切换应用池版本

应用此前在其他VM通过复制WebUi文件夹即可正常运行,正常环境访问基础URL会自动重定向至/WebUi,当前环境无该重定向。

疑问

  1. 还需检查哪些内容?
  2. 是否可导出正常VM的IIS配置与问题环境对比?

排查建议与解决方案

一、补充检查项

  • 站点默认文档配置:确认IIS站点的默认文档列表中包含MVC应用的起始页(如index.cshtml、对应路由的默认页)。当前错误中Handler为StaticFile,说明IIS仅尝试寻找静态默认文件,未触发ASP.NET路由逻辑。
  • ASP.NET路由模块注册:检查Web.config中是否注册了UrlRoutingModule-4.0,路由规则是否正确。若路由模块未启用,会导致MVC路由无法解析,返回404。
  • 应用池标识权限细节:确认应用池标识(ApplicationPoolIdentity)对WebUi文件夹及子目录(尤其是bin目录)拥有读取和执行权限,避免因权限不足导致无法加载程序集。
  • IIS模块重新注册:执行对应.NET Framework版本的注册命令修复模块关联,比如针对64位4.8版本:
    %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
    
  • 部署包完整性验证:解压WebUi.zip确认Views文件夹、路由配置相关文件是否齐全,避免部署过程中遗漏核心文件。
  • 重定向规则检查:对比正常VM的Web.config或IIS站点配置,确认是否存在URL重定向规则(自动跳转到/WebUi),当前环境可能缺失该规则。

二、IIS配置对比方法

可以导出两台VM的IIS配置进行差异对比,步骤如下:

  1. 在正常VM执行命令导出配置:
    %windir%\system32\inetsrv\appcmd.exe list site "MySite" /config /xml > C:\normal-site-config.xml
    %windir%\system32\inetsrv\appcmd.exe list apppool "DefaultAppPool" /config /xml > C:\normal-apppool-config.xml
    
  2. 在问题VM执行相同命令导出配置:
    %windir%\system32\inetsrv\appcmd.exe list site "MySite" /config /xml > C:\problem-site-config.xml
    %windir%\system32\inetsrv\appcmd.exe list apppool "DefaultAppPool" /config /xml > C:\problem-apppool-config.xml
    
  3. 使用文本对比工具(如Beyond Compare)对比XML文件,重点关注站点默认文档、模块注册、路由配置、应用池.NET版本及管道模式等差异点。

内容的提问来源于stack exchange,提问作者guidempty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 15:27:34