0

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

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

这是我的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 - 未找到错误。

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

4

2 回答 2

1

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

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

于 2013-06-19T14:34:22.670 回答
0

将 ASP.NET MVC 与不同版本的 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}");
于 2013-06-20T10:39:36.453 回答