【问题标题】:IIS 7 Error: Cannot execute a program. The command being executed was csc.exe (ApplicationPoolIdentity default settings)IIS 7 错误:无法执行程序。正在执行的命令是 csc.exe(ApplicationPoolIdentity 默认设置)
【发布时间】:2016-09-22 11:18:22
【问题描述】:

这是我在 SO 中的第一个问题,如果我有一些语法错误,请向我道歉。

问题描述:

我在 IIS 7 (Windows Server 2008) 和 SQL Server 2008 R2 上安装了 32 位基于 MVC 5 的 CRUD 系统,安装在多台服务器上,自 2015 年 8 月起提供公司内部网管理服务。 几个月来,它们都运行顺利,没有任何问题。但是,昨天我发现我无法通过以下消息访问 172.16.1.101 服务器上的站点根页面:

> Server Error in '/' Application.

> [Win32Exception (0x80004005): Access is denied]

>[ExternalException (0x80004005): Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig /fullpaths @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\-(random 8-digit hex)-\-(random 8-digit hex)-\-(random 8-char base64).cmdline".]
System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) +3365
System.CodeDom.Compiler.Executor.ExecWaitWithCapture(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) +8591876
Microsoft.CSharp.CSharpCodeGenerator.Compile(CompilerParameters options, String compilerDirectory, String compilerExe, String arguments, String& outputFile, Int32& nativeReturnValue, String trueArgs) +331
Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames) +784
Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames) +170
System.Web.Compilation.AssemblyBuilder.Compile() +12440424
System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +303
System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +12978145
System.Web.Compilation.BuildManager.CompileGlobalAsax() +50
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +665

>[HttpException (0x80004005): Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig /fullpaths @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\-(random 8-digit hex)-\-(random 8-digit hex)-\-(random 8-char base64)-.cmdline".]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +80
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +1142
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1193

>[HttpException (0x80004005): Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig /fullpaths @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\-(random 8-digit hex)-\-(random 8-digit hex)-\-(random 8-char base64)-.cmdline".]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12980692
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12820285

这是发生异常时的事件日志:

>IIS 7 Event Log

>Event code: 3005 

>Event message: An unhandled exception has occurred. 

>Event time: 5/24/2016 1:42:08 PM 

>Event time (UTC): 5/24/2016 6:42:08 AM 

>Event ID: 062751a2dc724be9af5de99014e58a47 

>Event sequence: 2 

>Event occurrence: 1 

>Event detail code: 0 

>Application information: 

>Application domain: /LM/W3SVC/3/ROOT-1-131085457263004464 

>Trust level: Full 

>Application Virtual Path: / 

>Application Path: E:\Test\ 

>Machine name: -- edited --

>Process information: 

>Process ID: 1172

>Process name: w3wp.exe 

>Account name: IIS APPPOOL\ASP.NET v4.0 

>Exception information:

>Exception type: HttpException

>Exception message: Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig /fullpaths @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\-(random 8-digit hex)-\-(random 8-digit hex)-\-(random 8-char base64)-.cmdline".
   at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
   at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
   at System.Web.Compilation.BuildManager.CallAppInitializeMethod()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

>Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig /fullpaths @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\-(random 8-digit hex)-\-(random 8-digit hex)-\-(random 8-char base64).cmdline".
   at System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine)
   at System.CodeDom.Compiler.Executor.ExecWaitWithCapture(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine)
   at Microsoft.CSharp.CSharpCodeGenerator.Compile(CompilerParameters options, String compilerDirectory, String compilerExe, String arguments, String& outputFile, Int32& nativeReturnValue, String trueArgs)
   at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
   at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames)
   at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile(CompilerParameters options, String[] fileNames)
   at System.Web.Compilation.AssemblyBuilder.Compile()
   at System.Web.Compilation.BuildProvidersCompiler.<PerformBuild>b__1(AssemblyBuilder assemblyBuilder)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass32`2.<PartitionerForEachWorker>b__30()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass11.<ExecuteSelfReplicating>b__10(Object param0)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
   at System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed)
   at System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories)
   at System.Web.Compilation.BuildManager.CompileResourcesDirectory()
   at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()

>Access is denied

>Request information:

>Request URL: //172.16.1.101/

>Request path: /

>User host address: //172.16.1.101

>User:

>Is authenticated: False

>Authentication Type:

>Thread account name: IIS APPPOOL\ASP.NET v4.0

>Thread information:

>Thread ID: 5

>Thread account name: IIS APPPOOL\ASP.NET v4.0

>Is impersonating: True

>Stack trace:    at >System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
   at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
   at System.Web.Compilation.BuildManager.CallAppInitializeMethod()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)


>Custom event details: 

有时消息显示\Temporary ASP.NET Files\tls 目录,而不是\Temporary ASP.NET Files\root 目录。

IIS 7 服务器配置为其默认状态和单个池,默认情况下没有任何运行的 Web 服务(仅基本配置),包括 XML(反)序列化程序。

主要以为我的IIS系统账户权限错误,我将权限设置为“完全控制”没有成功。

因此,根据消息,预计服务器端缺少文件编译,尝试通过此命令在 CMD 上手动编译 cmdline 文件

csc.exe /noconfig /fullpaths @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root-(随机 8 位十六进制)--(随机 8 位十六进制)--(随机 8-char base64).cmdline"

提供错误:

致命错误 CS2021:文件名 '@C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root-(随机 8 位十六进制)--(随机 8 位十六进制) --(random 8-char base64).cmdline' 太长或无效

错误 CS2011: 打开响应文件时出错 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\root-(随机 8 位十六进制)--(随机 8 位十六进制)--(随机 8- char base64).cmdline' -- '系统找不到指定的文件。 '

不会放弃,我对这个问题进行了谷歌搜索,并在SO上找到了相关的类似问题:

Problems publishing a website on smarterasp.net with csc.exe file included?

https://stackoverflow.com/questions/37146958/an-unhandled-exception-was-generated-during-the-execution-of-the-current-web-re

但是,在为实时服务器实现编译项目时,我既没有安装“Microsoft.CodeDom.Providers.DotNetCompilerPlatform”包,也没有使用 SOAP,并且在 web.config 上已经有 'identity impersonate="true"' 属性但无济于事.

接下来,我使用“高级设置”选项配置了与站点对应的 IIS 应用程序池,将身份部分从“ApplicationPoolIdentity”更改为“LocalSystem”,有趣的是,访问根页面时的 YSOD 消失了。我试图在“ApplicationPoolIdentity”上将其改回,而 YSOD 又转回来了。

即使通过LocalSystem身份暂时解决了问题,我仍然很好奇为什么会发生错误而没有任何系统故障的迹象。我想在这里问两个问题:

  1. 谁能解释为什么 ApplicationPoolIdentity 选项在这种情况下不起作用?

  2. 我可以采取哪些步骤来缓解其他服务器的此问题,即使它们的默认设置和 ApplicationPoolIdentity 已设置?

tl;dr:在 IIS 7 服务器上使用默认配置的 ApplicationPoolIdentity 一直有效,直到昨天我在没有应用 XML 序列化程序或 Web 服务的服务器上遇到上述 YSOD,请帮助我解释或描述服务器上已经发生了什么问题的详细信息以及缓解它的方法。

PS:写的目录路径中的“-”和“--”符号应替换为“\”。

【问题讨论】:

  • 您在哪个 .NET Framework 上创建了项目?您在这台 IIS 机器上安装的 .NET 框架版本是什么?
  • 有同样的问题。将身份切换到 NetworkService 也让我的网站刚刚备份(谢谢)。我最后一次推送构建是在您发布此内容之前。也许在 5 月的某个时候有一个 MS 补丁导致了这种情况?你有想过吗?

标签: c# asp.net asp.net-mvc asp.net-mvc-5 iis-7


【解决方案1】:

@machj 在我删除此部分后解决了我的问题:

 <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

【讨论】:

    【解决方案2】:

    在我的虚拟主机上,它帮助我从 web.config 中删除了此部分:

      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs"
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
        </compilers>
      </system.codedom>
    

    【讨论】:

      【解决方案3】:

      我知道这已经很老了,但过去几天我遇到了这个问题,我不得不在谷歌搜索中走得很远才能找到解决方案。

      以防万一其他人遇到此问题并且没有发现任何对您有用的文件夹删除。微软的这个工具可以为您完成这项工作!

      http://www.microsoft.com/en-us/download/details.aspx?id=30135

      【讨论】:

        【解决方案4】:

        在我的情况下,将权限添加到本地帐户“IIS_IUSRS”以在 Web 应用程序运行的目录上读取和执行已解决问题。

        【讨论】:

          【解决方案5】:

          从 nuget 包中卸载 DotNetCompilerPlatform

          【讨论】:

          • 谢谢!!!由于运行 csc.exe 的安全问题,这阻止了我将默认 ASP.Net 应用程序模板发布到共享 IIS 主机
          猜你喜欢
          • 2011-01-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-12
          • 1970-01-01
          • 1970-01-01
          • 2019-07-22
          • 2011-10-01
          相关资源
          最近更新 更多