有一些原因可能会导致该错误:
MVC 库的问题
The production server might not have the MVC libraries stored in the GAC. To fix this, all you have to do is go into your MVC project's References
pane/folder and find System.Web.Mvc
, System.Web.Routing
, and System.Web.Abstractions
. Now, select them by Ctrl clicking on them, and set Copy Local to true in the Properties window.
在发布到服务器之前很难知道是否是这种情况,因此我建议仅将程序集设置为始终复制到本地。
登陆页面
您的目标网页可能有问题。根据我使用 ASP.NET MVC 的经验,我发现 IIS 需要一个登录页面才能正常运行。我正在使用 ASP.NET MVC 2 模板中包含的页面。您应该将我的与您的进行比较,看看您是否拥有所需的一切:
默认.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNamespace._Default" %>
<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%>
默认.aspx.cs:
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
namespace YourNamespace
{
public partial class _Default : Page
{
public void Page_Load(object sender, System.EventArgs e)
{
// Change the current path so that the Routing handler can correctly interpret
// the request, then restore the original path so that the OutputCache module
// can correctly process the response (if caching is enabled).
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
}
}
}
权限
根据您获得的第一个 HTTP 状态代码,可能存在权限问题。这包含 MVC 应用程序的文件夹必须定义为应用程序并设置为适当的权限.
通过 IIS 可以很容易地完成这两件事。但是,您可能无权访问 IIS;如果你这样做,你就非常幸运了!
否则,您可以使用以下命令通过 FTP 更改权限chmod
命令。您可以通过Filezilla进行连接,Filezilla是一个非常好的开源FTP客户端,只需通过右键单击+对话框即可完成。
至于将文件夹定义为应用程序,您应该检查是否可以通过主机提供给您的任何 IIS 东西来完成此操作。如果没有,请联系他们并要求他们进行设置。
祝你好运!希望我有所帮助。