【问题标题】:In ASP.NET MVC, why do I get 404 errors after Publishing my website?在 ASP.NET MVC 中,为什么在发布我的网站后会出现 404 错误?
【发布时间】:2009-08-28 08:38:04
【问题描述】:

我还是 ASP.NET MVC 的新手,我在路由方面有点挣扎。

使用 ASP.NET 开发服务器(直接从 Visual Studio 运行),我的应用程序可以毫无问题地找到它的视图。使用标准的 ASP.NET URL - http://localhost:1871/InterestingLink/Register

但是,当我将网站发布到 IIS 并通过 http://localhost/MyFancyApplication/InterestingLink/Register 访问它时,我收到 404 错误。

对可能出现的问题有什么建议吗?

更多信息...

这是我的 global.asax 文件的样子(标准):

public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }

我的控制器也很简单:

public class InterestingLinkController : Controller
{
    public ActionResult Register()
    {
        return View("Register");
    }
}

【问题讨论】:

    标签: asp.net-mvc routing


    【解决方案1】:

    我知道出了什么问题。问题实际上是 IIS5(在 Windows XP 中)在 URL 不包含 .ASPX 时不会启动 ASP.NET。解决此问题的最简单方法是将“.aspx”添加到 global.asax 中的控制器部分。例如:

    routes.MapRoute(
                    "Default",                                              
                    "{controller}.aspx/{action}/{id}",                      
                    new { controller = "Home", action = "Index", id = "" }  
                );
    

    不漂亮,但可以。

    【讨论】:

      【解决方案2】:

      很多事情可能是错误的:

      • IIS 虚拟目录和应用程序设置是否正确?
      • 是否调用了 ASP.NET 应用程序? (在Application_StartApplication_BeginRequest 中添加一些日志记录/断点)

      只是一个开始。您将不得不应用通常的调试方法。

      (为了避免这样的问题,我很少使用开发服务器并且一直使用 IIS:最困难的事情是记住每次都运行 VS 提升。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-02-26
        • 2022-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-07
        相关资源
        最近更新 更多