asp.net-mvc - 无法访问 MVC5 编译 View

标签 asp.net-mvc visual-studio

我们一直在尝试为我们的应用程序预编译 View ,以缩短初始表单显示的渲染时间。

我们使用 Visual Studio 2017、MVC 5、MS Membership 进行安全登录。

在没有“发布期间预编译”的情况下发布到 Web 应用程序站点时,设置所有构建,应用程序按预期运行,并显示登录表单。

当设置“发布期间预编译”时,构建正常。

但是启动应用程序时,我们收到“HTTP 错误 404.0 - 未找到”错误 并且没有显示登录屏幕!

我已检查文件夹的安全性,位置路径权限允许所有用户。

在设置预编译的情况下发布时,我收到以下警告;

2>ASPNETCOMPILER(0,0): Warning : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Microsoft.ReportViewer.WebDesign, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91. The dependencies are: System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. 2>ASPNETCOMPILER(0,0): Warning : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Microsoft.ReportViewer.Design, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91. The dependencies are: System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. 2>ASPNETCOMPILER(0,0): Warning : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. The dependencies are: System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly.

我尝试通过将装配线添加到 web.config 部分来消除这些警告,但没有效果。

最佳答案

在没有看到你的 .config 的情况下的最佳猜测或.csproj文件的问题是您在 Web.config 中缺少以下部分文件:

<system.web>
  <compilation>
    <assemblies>
      <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    </assemblies>
  </compilation>
<system.web>

仅当引用的 DLL 位于 GAC 中时,此方法才有效。如果不是:

  1. 创建 /Bin网站根目录中的文件夹。
  2. 将您的 DLL 复制到此处。
  3. 请勿在 web.config 中添加引用。

引用文献:

如果这不起作用

Visual Studio 是一个很棒的工具。但它不太擅长在具有多个项目的解决方案之间甚至项目文件和配置文件之间保持依赖关系同步。通常,当您需要升级或降级依赖项时,主项目的 .csproj 之间将不可避免地出现不一致。文件和一个或多个依赖程序集 .csproj文件,或者甚至可能与 .config 不同步文件。

解决此类场景的唯一 100% 可靠方法是手动检查每个依赖项并确保所有项目和配置文件中的版本一致。

Visual Studio 2017

幸运的是,在 VS 2017 中,他们使这变得更容易做到。您现在只需右键单击该项目并选择 Edit <projectName>.csproj .

Edit Project in Visual Studio 2017

Visual Studio 的早期版本

  1. 在解决方案资源管理器中右键单击您的项目节点,然后单击 Unload Project .
  2. 再次右键单击项目节点,然后单击 Edit <projectName>.csproj .

寻找什么

Here is an example通过这种方式解决了 MVC 版本不匹配的问题。从 MVC 5 模板创建一个新项目来查看更新后的项目应该是什么样子,然后比较 Web.config 之间的差异可能会有所帮助。 , Views/Web.config.csproj文件,然后循环遍历其余每个依赖项,确保版本号一致且最新。

请务必检查 .csproj 是否文件正在使用 MSBuild conditions ,因为 Visual Studio 无法更新这些,而且它们往往是升级时出现问题的主要根源。

编辑

In IIS I set up a Failed Request Trace and the first item created contained; ModuleName UrlAuthorization Notification AUTHORIZE_REQUEST HttpStatus 401 HttpReason Unauthorized etc...

该消息表明您的应用程序已设置为使用 UrlAuthorization,经过进一步研究,它似乎可以配置为 IIS URL Authorization or ASP.NET URL Authorization

如果使用 ASP.NET URL 授权,您将有一个像这样的 web.config 条目

<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" preCondition="managedHandler" />

如果使用 IIS URL 授权,您将有一个像这样的 web.config 条目

<add name="UrlAuthorizationModule" image="%windir%\System32\inetsrv\urlauthz.dll" />

我从 VS 2017 模板(带有个人用户帐户)创建了一个新的 MVC 5 项目,这两个项目都不是典型的 MVC 5 应用程序。我不会告诉您删除这些内容就是解决方案,因为您的应用程序使用 URL 授权可能有一些正当理由。显然,这仍然是应用程序锁定文件的最佳方式,这样在没有登录的情况下就无法提供服务。尽管如此,如果可以通过删除您正在使用的模块来证明这是根本原因,那么它就可以了解决如何配置 URL 授权模块以与 MvcBuildViews 一起使用的问题已启用。

关于asp.net-mvc - 无法访问 MVC5 编译 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48333300/

相关文章:

c# - 应该抛出哪个异常?

asp.net-mvc - MVC : How to make DropdownList field (with Chosen Plugin) Required

jquery - 使用 jquery 重置 MVC 表单

asp.net - 通过命令行使用 WebGrease 时出现 System.IO.FileNotFoundException

visual-studio - Visual Studio 中 eclipse 的 ALT+UP/DOWN(移动线)相当于什么?

html - MVC Razor View Engine,在引号之间添加逻辑

c# - 在 C# 项目的 Visual Studio 中,要中断的异常列表存储在哪里?

c# - c# WinForm 中字符串的长度

c# - 验证以确保时差在 2 小时以内

javascript - 包括特定于 ASP.NET MVC4 View 或部分 View 的脚本