【问题标题】:ASP.Net MVC 2: My controller actions are not being calledASP.Net MVC 2:我的控制器动作没有被调用
【发布时间】:2009-11-26 07:02:45
【问题描述】:

我不确定发生了什么,但突然我的控制器操作没有被调用。这个项目一整天都运行良好,但是现在当我运行它时(在 Cassini 或 IIS 7 中)我得到“Internet Explorer 无法显示网页”。没有服务器错误,甚至没有 404 或 500 错误。

在单步执行代码时,我可以看到在应用程序启动期间路由已正确注册。然后在正确的控制器上调用构造函数和 Initialize 方法......什么都没有。我能够检查进入控制器上 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 方法。传递给 Initialize 方法的 requestContext 包含正确的路由数据。一旦 Initailize 方法完成执行,我就会收到“Internet Explorer 无法显示网页”消息。

我的 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);
    }
}

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    好吧,我已经解决了我的问题,事实证明它与 MVC 或我的代码无关,真的。对系统事件日志的检查显示我的本地计算机上存在一系列 SSL 错误。我项目中的控制器使用 [RequreHttps] 属性进行装饰,因为我需要通过 SSL 提供该站点。自签名证书在我的本地机器上测试时工作正常,但突然间就不行了。但是,这是一个完全独立的问题,如有必要,我会将其作为单独的问题发布。感谢所有调查此问题的人,感谢您抽出宝贵时间。

    【讨论】:

      猜你喜欢
      • 2016-12-03
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      相关资源
      最近更新 更多