代码之家  ›  专栏  ›  技术社区  ›  Jeff French

ASP.NET MVC 2:未调用我的控制器操作

  •  1
  • Jeff French  · 技术社区  · 15 年前

    我不知道发生了什么,但是突然我的控制器动作没有被调用。这个项目一整天都在正常工作,但现在当我运行它(在Cassini或IIs7中)时,我得到“InternetExplorer无法显示网页”。没有服务器错误,甚至没有404或500错误。

    在单步执行代码的过程中,我可以看到在应用程序启动期间正确注册了路由。在正确的控制器上调用Constructor和Initialize方法,然后…..无。我能够检查进入我的控制器上的初始化方法的requestContext,并且框架已经获取了正确的路由数据。我所有的控制器都会发生这种情况。另一个MVC项目在同一台机器上运行得很好。

    我完全迷路了。任何帮助都将非常感谢,因为我有12月1日这个项目的最后期限。

    谢谢, 杰夫·弗伦奇

    以下是我的一些代码:

    我的家庭控制器不工作:

    public class HomeController : Controller
    {
        public HomeController():base()
        {
    
        }
    
        protected override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);
        }
    
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
        }
    
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
        }
    
        protected override void HandleUnknownAction(string actionName)
        {
            base.HandleUnknownAction(actionName);
        }
    
        public ActionResult Index()
        {
            //if (!Request.IsAuthenticated)
            //    return RedirectToAction("LogOn", "Account");
            return View();
        }
    
        public ActionResult About()
        {
            return View();
        }
    }
    

    我添加了重写,这样我就可以在它们中设置断点来查看被调用的内容。先调用构造函数,然后调用初始化方法。传递给initialize方法的requestContext包含正确的路由数据。一旦initailize方法完成执行,我就会收到“Internet Explorer cannot display the webpage”消息。

    我的Glogal.asax:

    public class MvcApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                "Default", // Route name
                "{tenant}/{controller}/{action}/{id}", // URL with parameters
                new {tenant = "demo", controller = "Home", action = "Index", id = ""} // Parameter defaults
                );
        }
    
        public void RegisterViewEngines(ViewEngineCollection engines)
        {
        }
    
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
        }
    
    
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            RegisterViewEngines(ViewEngines.Engines);
        }
    }
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Jeff French    15 年前

    嗯,我已经解决了我的问题,事实证明这与MVC或我的代码无关,真的。对系统事件日志的检查揭示了本地计算机上的一系列SSL错误。我的项目中的控制器被修饰成了[requerehtps]属性,因为我需要通过SSL服务这个站点。自签名证书在我的本地机器上测试时一直工作正常,但突然间就不正常了。然而,这是一个完全独立的问题,如果必要的话,我会把它作为一个独立的问题发布。感谢所有研究这个问题的人,我很感谢你的时间。