Asp.net-Mvc
在 IIS 7 中執行 MVC3 應用程序時出現問題
我在執行 Windows 7 Home-64 位的電腦上獲取在 IIS7 中執行的 MVC 3 項目時遇到問題。這就是我所做的。
- 安裝了 IIS 7。
- 訪問伺服器並獲得 IIS 歡迎頁面。
- 創建了一個名為 d:\MySite 的目錄並將 MVC 應用程序複製到其中。(MVC 應用程序只是您在 Visual Studio 中創建新的 MVC3 項目時創建的標準應用程序。它只顯示一個首頁和一個帳戶登錄頁面。它在 Visual Studio 開發伺服器中執行良好,我也將其複制了出來到我的託管網站,它在那里工作正常)
- 啟動 IIS 管理控制台。
- 停止預設站點。
- 添加了一個名為“MySite”的新站點,其物理目錄為“d:\Mysite”
- 將名為 MySite 的應用程序池更改為使用 .Net Framework 4.0,集成管道
當我在瀏覽器中訪問該站點時,我會獲得 d:\MySite 目錄中的文件列表。就好像 IIS 沒有將 d:\MySite 的內容辨識為 MVC 應用程序一樣。
我需要做什麼來解決這個問題?
根據要求,這是 web.config:
<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=152368 --> <configuration> <connectionStrings> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0"> <assemblies> <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies> </compilation> <authentication mode="Forms"> <forms loginUrl="~/Account/LogOn" timeout="2880" /> </authentication> <membership> <providers> <clear/> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <profile> <providers> <clear/> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /> </providers> </profile> <roleManager enabled="false"> <providers> <clear/> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager> <pages> <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.Routing" /> <add namespace="System.Web.WebPages"/> </namespaces> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
我也在“ServerFault”上發布了這個問題,並在此處獲得了該問題的解決方案。
答案是:
由於 IIS 是在 .NET 4 之後安裝的,您可能需要執行aspnet_regiis.exe工具來向 IIS 註冊所有 .NET 4 內容。