0
我在部署MVC VS2015模板创建一个MVC 5 Web应用程序“‘ViewBag’这个名字不会在目前情况下存在”。该应用程序里工作大VS2015发布然而之后(文件系统,然后复制)到Windows 2008 R2服务器/ IIS 7.5 - 将浏览器指向应用程序根给出了上面的错误。指着/帐号/登录给出了略有不同:在服务器部署(MVC5/IIS 7.5)
"The name 'model' does not exist in the current context"
我读过很多答案对于这个错误,但没有帮助,没有具体针对我的ENV版本。香港专业教育学院已经尝试过:
- 部署到虚拟目录
- 部署到根目录的空白网站
- 添加
- 验证应用程序池.NET 4.0 /综合
- 添加web.config中视图文件夹(默认情况下不创建MVC 5)
我错过了什么?
我得到(允许在web.config中详细的错误信息之后)的错误:
我的错误:
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: CS0103: The name 'ViewBag' does not exist in the current context
Source Error:
Line 1: @{
Line 2: ViewBag.Title = "Home Page";
Line 3: }
Line 4:
我的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>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=win10nh\sqlexpress;Initial Catalog=*****;uid=sa;password=*****;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /><add name="DefaultConnection" connectionString="Data Source=win10nh\sqlexpress;Initial Catalog=*****;uid=sa;password=*****;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="*****Entities1" connectionString="metadata=res://*/Models.EFmodel.Model1.csdl|res://*/Models.EFmodel.Model1.ssdl|res://*/Models.EFmodel.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=win10nh\sqlexpress;initial catalog=*****;user id=sa;password=*****;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /><add name="*****Entities" connectionString="metadata=res://*/Models.EFmodel.Model1.csdl|res://*/Models.EFmodel.Model1.ssdl|res://*/Models.EFmodel.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=win10dev\sqlexpress;initial catalog=*****;user id=sa;password=*****;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<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>
<authentication mode="Forms">
<!--http://stackoverflow.com/questions/2454623/multiple-applications-using-same-login-database-logging-each-other-out-->
<!--<forms timeout="20" loginUrl="~/Account/Login" domain="gc.*****.com" />-->
<forms timeout="60" loginUrl="~/Account/Login" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" connectionStringName="ApplicationServices" type="System.Web.Security.SqlMembershipProvider" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" />
</providers>
</membership>
<roleManager enabled="true">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" connectionStringName="ApplicationServices" type="System.Web.Security.SqlRoleProvider" applicationName="/" />
</providers>
</roleManager>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
<!--<add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="sqlServerMembership" />-->
</providers>
<properties>
<!--add name="UiCulture" serializeAs="String" allowAnonymous="true" />-->
</properties>
</profile>
<!--<authentication mode="Forms" />-->
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<!--<remove name="FormsAuthentication" />-->
<!--<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />-->
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<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="0.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.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.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>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
恩科西的web.config文件,为感谢您的回答。 - 添加在根web.config“页面”标签 - 没有变化。 - 添加您建议的web.config Views文件夹 - 新的错误如下: 编译器错误消息:CS0234:类型或命名空间名称“HTTP”在命名空间“System.Net”不存在(是否缺少程序组装参考?) 源错误: 第26行:使用System.Web.Optimization; 27行:使用System.Web.Routing; 第28行:使用System.Net.Http; 第29行: 第30行: – user3104076
@ user3104076,我说加上'pages'到'system.web'标签,而不是根本。无论如何看起来你手上有更大的问题。尝试从头开始创建一个新项目,并将其配置与您的项目中不能正常工作的配置进行比较。应该给你一个关于什么可能导致你的问题的线索。 – Nkosi