2017-02-18 6 views
0

VS2015 MVCテンプレートで作成されたMVC 5 Webアプリケーションをデプロイします。このアプリケーションはVS2015の中でうまく動作します。ただし、Windows 2008 R2 Server/IIS 7.5に公開した後(ファイルシステムにコピーしてから)、ブラウザをアプリケーションのルートに向けると上記のエラーが発生します。 /アカウントを指す/ログインはわずかに異なるを与える:私はたくさんの答えを読んで、このエラーに関してはどれも助け、どれもが私のenvバージョンに固有ではなかったしました"サーバーのデプロイ時(MVC5/IIS 7.5)に、 'ViewBag'という名前が現在のコンテキストに存在しません。

"The name 'model' does not exist in the current context" 

。アイブ氏はすでに試した:

  • の確認アプリケーションプールがにweb.configファイルを追加するネット4 /統合
  • での追加ルートレベル空白のウェブサイトへ
  • を展開
  • 仮想ディレクトリへのデプロイビューフォルダ(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=&quot;data source=win10nh\sqlexpress;initial catalog=*****;user id=sa;password=*****;multipleactiveresultsets=True;application name=EntityFramework&quot;" 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=&quot;data source=win10dev\sqlexpress;initial catalog=*****;user id=sa;password=*****;multipleactiveresultsets=True;App=EntityFramework&quot;" 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=\&quot;Web\&quot; /optionInfer+" /> 
    </compilers> 
    </system.codedom> 
</configuration> 

答えて

0

はへpagesタグを追加してみてくださいconfigファイルのsystem.webタグ。

<pages controlRenderingCompatibilityVersion="4.5"> 
    <namespaces> 
    <add namespace="System.Web.Helpers" /> 
    <add namespace="System.Web.Mvc" /> 
    <add namespace="System.Web.Mvc.Ajax" /> 
    <add namespace="System.Web.Mvc.Html" /> 
    <add namespace="System.Web.Optimization" /> 
    <add namespace="System.Web.Routing" /> 
    <add namespace="System.Web.WebPages" /> 
    </namespaces> 
</pages> 

また、あなたが答えてくれてありがとうをViewsフォルダ

<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.0.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.Optimization"/> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="System.Net.Http" /> 
     </namespaces> 
    </pages> 
    </system.web.webPages.razor> 

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

    <system.web> 
    <httpHandlers> 
     <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> 
    </httpHandlers> 

    <!-- 
     Enabling request validation in view pages would cause validation to occur 
     after the input has already been processed by the controller. By default 
     MVC performs request validation before a controller processes the input. 
     To change this behavior apply the ValidateInputAttribute to a 
     controller or action. 
    --> 
    <pages 
     validateRequest="false" 
     pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
     pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
     userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <controls> 
     <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /> 
     </controls> 
    </pages> 
    </system.web> 

    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 

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

Nkosiのweb.configファイルを確認してください。 - ルートweb.configに "pages"タグを追加する - 変更しない。 - 表示されたweb.configをViewsフォルダに追加 - 新しいエラー: コンパイラエラーメッセージ:CS0234: 'Http'という名前の型または名前空間が 'System.Net'という名前空間に存在しません。アセンブリ参照?) ソースエラー: 行26:using System.Web.Optimization; 行27:using System.Web.Routing; 行28:using System.Net.Http; 行29: 行30: – user3104076

+0

@ user3104076、私は 'system.web'タグに' pages'を追加しました。あなたの手には大きな問題があるように見えます。新しいプロジェクトを一から作成して、その構成と、プロジェクト内で作業していないものとを比較してみてください。あなたの問題を引き起こしている可能性のあるものを手がかりにしてください。 – Nkosi

関連する問題