gpt4 book ai didi

iis - 如何修复不会编译简单应用程序的 IIS Express?

转载 作者:行者123 更新时间:2023-12-05 00:20:15 29 4
gpt4 key购买 nike

如果我创建一个新的空 MVC 应用程序,添加一个 Controller 和一个 View ,然后运行我会收到一个编译错误,该错误似乎来自 IISExpress,因为它在 Visual Studio 中没有显示为错误。

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: 'ViewData' is not declared. It may be inaccessible due to its protection level.

Source Error:

Line 1:  @Code 
Line 2: ViewData("Title") = "Index"
Line 3: End Code

Views web.config 似乎是正确的,因为它包含各种必需的命名空间:

<?xml version="1.0"?>

<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>

<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="MVCAjaxWorkbench" />
</namespaces>
</pages>
</system.web.webPages.razor>

<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>

<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>

而且主要的 web.config 似乎也是正确的:

<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5.1"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

我认为我安装的 IISExpress 出了点问题。我已经查看了使用 IIS instead of IISExpress 的选项我真的更愿意坚持使用 IISExpress,但只是重新安装它没有任何区别。我的下一步是尝试重新安装 Visual Studio,但我宁愿尽可能避免这样做,因为它本身往往会产生副作用。

如何修复我的 IISExpress 安装,使其在 Visual Studio 中正常运行?

最佳答案

实际上,我通过执行以下操作成功地完成了这项工作:

  • 卸载 IISExpress
  • 运行 Visual Studio 2013 的“修复”安装
  • 清理解决方案并在 System.Web.MVC (following some of the answers in this question) 的引用属性中设置 Copy Local = True
  • 使用包管理器对话框更新所有 MS 和 .NET DLL
  • 更新 JQuery 和 Bootstrap(仅作为更新 DLLS 的结果)

虽然我怀疑它正在设置 Copy Local = True 但我无法确定其中哪一个是关键步骤,但 MS 更新 appears to be the source of the problem .

关于iis - 如何修复不会编译简单应用程序的 IIS Express?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26969569/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com