MVC5 IIS 7.5+ 部署
1、首先 将程序的NuGet包 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 这个包卸载掉 防止生成csc.exe 的一堆文件
2、配置网站根web.config
1 <appSettings> 2 <add key="webpages:Version" value="3.0.0.0" /> 3 <add key="webpages:Enabled" value="false" /> 4 <add key="ClientValidationEnabled" value="true" /> 5 <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 6 </appSettings>
1 <connectionStrings> 2 <!--数据库连接字符串的name不能更改--> 3 <add name="dbMSSQL" connectionString="server=.\MSSQL;database=dbname;uid=sa;pwd=123456" /> 4 </connectionStrings> 5 <system.web> 6 <authentication mode="None" /> 7 <compilation debug="true" targetFramework="4.5" /> 8 <!--设置全局上传大小--> 9 <httpRuntime maxRequestLength="2000000" targetFramework="4.5" requestValidationMode="2.0" /> 10 <httpModules> 11 <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 12 </httpModules> 13 <customErrors mode="Off" defaultRedirect="~/error/404.htm"> 14 <error statusCode="404" redirect="~/error/404.htm" /> 15 <error statusCode="500" redirect="~/error/500.htm" /> 16 </customErrors> 17 18 <pages enableEventValidation="false" validateRequest="false" controlRenderingCompatibilityVersion="4.5" clientIDMode="AutoID"> 19 20 </pages> 21 </system.web> 22 23 <system.webServer> 24 <modules runAllManagedModulesForAllRequests="true"> 25 <remove name="FormsAuthentication" /> 26 <remove name="ApplicationInsightsWebTracking" /> 27 <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 28 </modules> 29 <validation validateIntegratedModeConfiguration="false" /> 30 </system.webServer> 31 <runtime> 32 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 33 <dependentAssembly> 34 <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /> 35 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 36 </dependentAssembly> 37 <dependentAssembly> 38 <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" /> 39 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 40 </dependentAssembly> 41 <dependentAssembly> 42 <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" /> 43 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 44 </dependentAssembly> 45 <dependentAssembly> 46 <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /> 47 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 48 </dependentAssembly> 49 <dependentAssembly> 50 <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> 51 <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 52 </dependentAssembly> 53 <dependentAssembly> 54 <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 55 <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 56 </dependentAssembly> 57 <dependentAssembly> 58 <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 59 <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 60 </dependentAssembly> 61 <dependentAssembly> 62 <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 63 <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 64 </dependentAssembly> 65 <dependentAssembly> 66 <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 67 <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 68 </dependentAssembly> 69 <dependentAssembly> 70 <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 71 <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 72 </dependentAssembly> 73 </assemblyBinding> 74 </runtime>
3、配置View文件夹内的web.config
1 <configuration> 2 <configSections> 3 <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"> 4 <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" /> 5 <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" /> 6 </sectionGroup> 7 </configSections> 8 9 <system.web.webPages.razor> 10 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 11 <pages pageBaseType="System.Web.Mvc.WebViewPage"> 12 <namespaces> 13 <add namespace="System.Web.Mvc" /> 14 <add namespace="System.Web.Mvc.Ajax" /> 15 <add namespace="System.Web.Mvc.Html" /> 16 <add namespace="System.Web.Routing" /> 17 <add namespace="websitename" /> 18 </namespaces> 19 </pages> 20 </system.web.webPages.razor> 21 22 <appSettings> 23 <add key="webpages:Enabled" value="false" /> 24 </appSettings> 25 26 <system.webServer> 27 <validation validateIntegratedModeConfiguration="false"/> 28 <modules runAllManagedModulesForAllRequests="true"/> 29 <handlers> 30 <remove name="BlockViewHandler"/> 31 <add name="html_PageHandlerFactory" path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" /> 32 <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> 33 </handlers> 34 35 </system.webServer> 36 37 <system.web> 38 <compilation> 39 <assemblies> 40 <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 41 </assemblies> 42 </compilation> 43 </system.web> 44 </configuration>
其中主要
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
这2句
排除403的错误 多数都是加这两句就可以
IIS方面不废话直接上图
程序池设置
网站映射模块
IIS主页的ISAP和CGI模块