在ASP.NET MVC中,为什么在发布我的网站后会出现404错误?

时间:2009-08-28 08:38:05

标签: asp.net-mvc routing

我还是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");
    }
}

2 个答案:

答案 0 :(得分:2)

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

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

不漂亮,但它会做。

答案 1 :(得分:1)

很多事情可能都是错的:

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

刚开始。您将不得不应用通常的调试方法。

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

相关问题