【问题标题】:publish asp.net mvc 4 site gave 404 on IIS 6 host发布 asp.net mvc 4 站点在 IIS 6 主机上给出了 404
【发布时间】:2013-06-13 08:22:32
【问题描述】:

新创建的 ASP.Net MVC 4,带有 VS Express 2012 for Web 的 C# 项目,目标 .Net Framework 4.0 版(与远程主机相同)。
直接通过VS调试就是find。发布到本地文件夹后,[original:没有生成.aspx,只有sitename.dll,甚至还有原版.cshtml files] 并复制到 IIS Express C:\inetpub\www 文件夹,http://localhost/Home 就可以了。

但是当我将所有内容上传到主机时(根据 info.aspx,服务器信息:IIS 6.0,.Net 版本 4.0.30319.239),http://domain/Home 给出了page cannot be found 404 错误,这似乎就像一个路由问题。

这是我的 Web.config

<?xml version="1.0" encoding="utf-8"?>
<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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-FireupCooking.Net4._0-20130620031747;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-FireupCooking.Net4._0-20130620031747.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <customErrors mode="Off" />
    <compilation targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <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.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

以下是bin/下的文件:

Antlr3.Runtime.dll
DotNetOpenAuth.AspNet.dll
DotNetOpenAuth.Core.dll
DotNetOpenAuth.OAuth.Consumer.dll
DotNetOpenAuth.OAuth.dll
DotNetOpenAuth.OpenId.dll
DotNetOpenAuth.OpenId.RelyingParty.dll
EntityFramework.dll
FireupCooking.Net4.0.dll
Microsoft.Web.Infrastructure.dll
Microsoft.Web.WebPages.OAuth.dll
Newtonsoft.Json.dll
System.Net.Http.dll
System.Net.Http.Formatting.dll
System.Net.Http.WebRequest.dll
System.Web.Helpers.dll
System.Web.Http.dll
System.Web.Http.WebHost.dll
System.Web.Mvc.dll
System.Web.Optimization.dll
System.Web.Razor.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
WebGrease.dll
WebMatrix.Data.dll
WebMatrix.WebData.dll

我还尝试了以下最小的web.config,info.aspx 仍然给出Server Application Unavailable错误更新:此文件现在显示服务器信息。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
</configuration>

静态文件 html、gif 和简单的 *.aspx*s 都可以。只有 MVC 路径 /Home/Index/Home 给出了 404 - not found 错误。

我应该改变什么才能让它工作?

【问题讨论】:

    标签: asp.net-mvc-4 visual-studio-2012 http-status-code-404 publish


    【解决方案1】:

    你在本地得到的是正确的。 .Csthml 文件是使用 Razor 时的网页。

    您是否在主机上正确设置了 IIS?您必须创建一个网站并确保应用程序池使用正确的 .Net 版本。

    【讨论】:

    • 哦,我明白了。谢谢。我在网上找到了一个info.apx,据说和phpinfo类似,实现了目标主机.Net Framework是2.0。现在我让提供商将它设置为 4.0,但 info.apx 给了我Server Application Unavailable。看了日志(好像只有访问日志),发现状态码500 0 0,没有其他信息。
    • 我将项目发布到本地文件系统,并复制到本地IIS Express文件夹,并成功访问了localhostlocalhost/Host。然后我将所有内容上传到远程主机,访问了访问过的 http://~domain~/Home,但这给了我 404
    • 当您尝试访问该页面时,您能否将您现在收到的确切信息发送给我?您是否还为应用程序设置了虚拟目录或个人网站?还可以尝试在该位置放置一个简单的 html 文件,以确保这是 IIS 配置的问题,而不是您的应用程序
    • 感谢您的回复。我只有 FTP 访问主机,所以不能做服务器端配置。我有一个类似系统的第二台主机,并试图将相同的文件放在那里。然后得知我必须在global.asax.cs 中注册路由器才能使 MVC 4 与 IIS 6 一起工作,之后它在第二台主机上工作。在所需的主机上,.html.gif 静态文件很好,但即使我现在访问简单的一行文件,我也只会得到“服务器应用程序不可用”。所以我猜是服务器配置问题,但不确定是什么。
    • 我几乎可以肯定它与服务器配置有关。看看是否有人可以为您检查。
    【解决方案2】:

    Using ASP.NET MVC with Different Versions of IIS (C#) 让共享主机 IIS 6 逐步使用 MVC 路由。它甚至在 VS 生成的页面上,但我忽略了它。

    所以对于其他有类似头痛的人来说,这里是重要的部分。
    1.假设它是一个共享主机,我们不能做太多的服务器配置。
    2. IIS 6、.Net 4.0,可能还有 Windows 2003

    在我们的 Asp.Net MVC 4 中,global.asax.cs 注册路由

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
            "Default",
            "{controller}.aspx/{action}/{id}",
            new { action = "Index", id = "" }
          );
    
        routes.MapRoute(
          "Root",
          "",
          new { controller = "Home", action = "Index", id = "root" }
        );
    }
    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);  //RouteConfig.RegisterRoutes didn't work
    }
    

    由于.aspx 文件被定向到ASP.Net 进行处理,这些路由规则将捕获http://domain/home.apspx/index 以调用HomeController.Index
    如果需要忽略某些文件,只需在前面添加一个忽略规则,如下所示

    routes.IgnoreRoute("Content/{*pathInfo}");
    routes.IgnoreRoute("info.aspx");
    
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    

    【讨论】:

      猜你喜欢
      • 2018-08-31
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      • 2010-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多