发布网站某些页面失败

时间:2020-03-05 18:53:46  来源:igfitidea点击:

发布网站时出现一个奇怪的问题。我继承了这个项目,问题在我到达之前就开始了,所以我不知道是什么情况导致了问题的产生。

基本上,网站项目下面的3个文件夹无法正确发布。当PrecompiledWeb传输到主机时,这三个文件夹必须从Visual Studio项目中手动复制(即,它们不再是已发布的版本)到主机才能正常工作。

如果保留了发布操作的结果,则文件夹中的任何页面都会导致以下错误:

Server Error in '/' Application.
  Unable to cast object of type
  'System.Web.Compilation.BuildResultNoCompilePage'
  to type
  'System.Web.Compilation.BuildResultCompiledType'.
  Description: An unhandled exception
  occurred during the execution of the
  current web request. Please review the
  stack trace for more information about
  the error and where it originated in
  the code.
  
  Exception Details:
  System.InvalidCastException: Unable to
  cast object of type
  'System.Web.Compilation.BuildResultNoCompilePage'
  to type
  'System.Web.Compilation.BuildResultCompiledType'.
  
  Source Error:
  
  An unhandled exception was generated
  during the execution of the current
  web request. Information regarding the
  origin and location of the exception
  can be identified using the exception
  stack trace below.
  
  Stack Trace:
  
  [InvalidCastException: Unable to cast
  object of type
  'System.Web.Compilation.BuildResultNoCompilePage'
  to type
  'System.Web.Compilation.BuildResultCompiledType'.]
  System.Web.UI.PageParser.GetCompiledPageInstance(VirtualPath
  virtualPath, String inputFile,
  HttpContext context) +254

  System.Web.UI.PageParser.GetCompiledPageInstance(String
  virtualPath, String inputFile,
  HttpContext context) +171

  URLRewrite.URLRewriter.ProcessRequest(HttpContext
  context) +2183

  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  +405    System.Web.HttpApplication.ExecuteStep(IExecutionStep
  step, Boolean& completedSynchronously)
  +65
  
  Version Information: Microsoft .NET
  Framework Version:2.0.50727.832;
  ASP.NET Version:2.0.50727.832

有谁知道这些页面无法正确发布的可能原因是什么?我所看到的任何东西都可能表明问题的根源?

添加:
每次都是完全干净的构建,因此旧的bin文件不存在问题。我还检查了bin文件夹中项目的日期戳,它们是最新的。

第二增加:
该项目最初是作为网站而不是Web应用程序创建的。抱歉,含糊不清。

解决方案

回答

我会尝试清洁bin \文件夹。
无论如何,我们的商店完全放弃了网站,转而使用Web表单应用程序,这可以说是更好的选择。

编辑:迁移如何到这里

回答

我们可能会考虑尝试使用Microsoft的Web部署项目。从本质上讲,它们使我们可以对MSBuild进行更多控制,但它可能有助于解决部署/预编译问题。

我们是否推断我们使用的是网站项目类型(而不是Web应用程序)?

回答

我猜是因为发布时,它正在编译Web站点项目,并且在不同文件夹或者子文件夹中的某个地方出现了重复的类名。确保检查继承标签和类名,以免将两个类称为同一类。当在编码和调试时它出现在不同的文件夹中时,这很好并且不会出错,但是当我们去发布/部署它时将出错。希望这是有道理的。

回答

不久前,我有一个类似的问题,发布会说成功,但是publish文件夹仍然是空的。

除了查看Web部署项目外,我们还应该将详细程度设置为Diagnostic(工具=>选项=>项目和解决方案=>生成并运行=> Msbuild项目生成输出详细程度)

就我而言,这显示了有意义的编译器错误,可以帮助我解决问题。

然后,我们还可以在shell提示中使用带有-errorstack指令的aspnet_compiler来显示其他错误。