asp.net-mvc 在 IIS 7 中运行 MVC3 应用程序的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5059897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:54:38  来源:igfitidea点击:

Problem running MVC3 app in IIS 7

asp.net-mvciis-7asp.net-mvc-3

提问by Mike Moore

I am having a problem getting a MVC 3 project running in IIS7 on a computer running Windows 7 Home-64 bit. Here is what I did.

我在运行 Windows 7 Home-64 位的计算机上获取在 IIS7 中运行的 MVC 3 项目时遇到问题。这是我所做的。

  1. Installed IIS 7.
  2. Accessed the server and got the IIS welcome page.
  3. Created a directory named d:\MySite and copied the MVC application to it. (The MVC app is just the standard app that is created when you create a new MVC3 project in visual studio. It just displays a home page and an account logon page. It runs fine inside the Visual Studio development server and I also copied it out to my hosting site and it works fine there)
  4. Started IIS management console.
  5. Stopped the default site.
  6. Added a new site named "MySite" with a physical directory of "d:\Mysite"
  7. Changed the application pool named MySite to use .Net Framework 4.0, Integrated pipeline
  1. 安装了 IIS 7。
  2. 访问服务器并获得 IIS 欢迎页面。
  3. 创建一个名为 d:\MySite 的目录并将 MVC 应用程序复制到其中。(MVC 应用程序只是在 Visual Studio 中创建新的 MVC3 项目时创建的标准应用程序。它只显示一个主页和一个帐户登录页面。它在 Visual Studio 开发服务器中运行良好,我也将其复制了出来到我的托管网站,它在那里工作正常)
  4. 启动 IIS 管理控制台。
  5. 停止了默认站点。
  6. 添加了一个名为“MySite”的新站点,物理目录为“d:\Mysite”
  7. 将名为 MySite 的应用程序池更改为使用 .Net Framework 4.0,集成管道

When I access the site in the browser I get a list of the files in the d:\MySite directory. It is as if IIS is not recognizing the contents of d:\MySite as an MVC application.

当我在浏览器中访问该站点时,我会得到 d:\MySite 目录中的文件列表。就好像 IIS 没有将 d:\MySite 的内容识别为 MVC 应用程序。

What do I need to do to resolve this?

我需要做什么来解决这个问题?

As requested, here is the web.config:

根据要求,这里是 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>

回答by Mike Moore

I posted this question on "ServerFault" as well and got a resolution to the issue here.

我也在“ServerFault”上发布了这个问题,并在这里解决了这个问题。

The answer is:

答案是:

Since IIS was installed after .NET 4, you likely need to run the aspnet_regiis.exetool to register all the .NET 4 stuff with IIS.

由于 IIS 是在 .NET 4 之后安装的,您可能需要运行aspnet_regiis.exe工具来向 IIS 注册所有 .NET 4 内容。

回答by Jan

I like to add some details:

我想补充一些细节:

After registering ASP.NET 4 using aspnet_regiis -iI also had to update the web application using aspnet_regiis -s W3SVC/1/ROOT/SampleApp1in order to fix the problem.

使用注册 ASP.NET 4 后,aspnet_regiis -i我还必须更新 Web 应用程序aspnet_regiis -s W3SVC/1/ROOT/SampleApp1以解决问题。

The /1/in W3SVC/1/ROOT/SampleApp1is the instance of your web application. You can find it by looking into your IIS Manager in the column ID.

/1/W3SVC/1/ROOT/SampleApp1你的web应用程序的实例。您可以通过查看列中的 IIS 管理器来找到它ID

The ROOT/SampleApp1in W3SVC/1/ROOT/SampleApp1is your application path. If you want to update all sites, just do aspnet_regiis -s W3SVC/.

ROOT/SampleApp1W3SVC/1/ROOT/SampleApp1为您的应用程序的路径。如果您想更新所有站点,只需执行aspnet_regiis -s W3SVC/.

Afterwards it worked fine for me.

之后它对我来说效果很好。

回答by Chris Williamson Hobbis

I had 403.14 errors when running an MVC 3 website on the server. Server was 32 bit. 2008. IIS7. The problem was that the HTTP Redirection feature was not installed. Server Manager -> Roles -> Web Server -> Roles Services -> HTTP Redirection. This is the only thing that fixed it for me. The web.config needed no change.

在服务器上运行 MVC 3 网站时出现 403.14 错误。服务器是 32 位的。2008. IIS7。问题是未安装 HTTP 重定向功能。服务器管理器 -> 角色 -> Web 服务器 -> 角色服务 -> HTTP 重定向。这是唯一为我修复它的东西。web.config 不需要更改。

回答by Bill

I think the majority of IIS7 website setup problems is due to folder security. If you try to create a website by copying the application folders directly from your dev environment to a folder not under wwwroot, the security on your folders will be wrong and you will fight it for hours getting ambiguous errors. The EASY way to get it correct, is to inspect and inetpub/wwwroot folder, examine it and add permissions to your folder, starting with computername\IIS_IUSRS and computername\Users. For mvc, make sure you have a web.config AND global.asax at the root. You do not need a default document for mvc and you should not allow directory browsing. If using aspnet_regiis, you may want to use the -ir if there are other sites being hosted on the machine.

我认为大多数 IIS7 网站设置问题是由于文件夹安全。如果您尝试通过将应用程序文件夹直接从您的开发环境复制到不在 wwwroot 下的文件夹来创建网站,则您的文件夹的安全性将是错误的,并且您将与它斗争数小时以获取不明确的错误。使其正确的简单方法是检查 inetpub/wwwroot 文件夹,检查它并向您的文件夹添加权限,从计算机名\IIS_IUSRS 和计算机名\用户开始。对于 mvc,请确保根目录下有 web.config 和 global.asax。您不需要 mvc 的默认文档,并且不应允许目录浏览。如果使用 aspnet_regiis,如果机器上托管了其他站点,您可能需要使用 -ir。

回答by LeoYoung

I didn't solve this problem until I install .net v4.0.30319 ,before that .net version on my machine is v4.0.30128 . It takes me a long time to figure out the problem,hope this can help someone.

在我安装 .net v4.0.30319 之前我没有解决这个问题,之前我机器上的 .net 版本是 v4.0.30128 。我花了很长时间才弄清楚问题,希望这可以帮助某人。

回答by SleeperService

Have you checked the websites default document in IIS is at the top of the list.

您是否检查过 IIS 中的网站默认文档位于列表顶部。

I think it defaults to default.asp with default.aspx either not there or at the bottom of the list

我认为它默认为 default.asp,而 default.aspx 要么不在那里,要么在列表的底部