使用VS Express 2012 for Web新建ASP.Net MVC 4,C#项目,目标.Net Framework 4.0版(与远程主机相同)。
通过VS直接进行调试。发布到本地文件夹后,[原文: 没有生成.aspx,只有 sitename.dll ,甚至有原始 .cshtml 文件]并复制到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 仍然提供服务器应用程序不可用错误。 更新:此文件现在显示服务器信息。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
静态文件html,gif和simple * .aspx * s都没问题。只有MVC pathes /Home/Index
和/Home
给出了 404 - not found 错误。
我应该改变什么来使其有效?
答案 0 :(得分:1)
你在当地获得的是正确的。 .Csthml文件是使用Razor时的网页。
您是否在主机上正确设置了IIS?您必须创建一个网站,并确保应用程序池使用正确的.Net版本。
答案 1 :(得分:0)
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}");