2013-05-08 79 views
4

我已经搜索了互联网的高低,并检查了所有以前回答的问题,但是我找不到相同的标题。未找到路径'/ Home'的控制器或未实施IController

我从操作方法在我的认证控制器返回RedirectToAction(“指数”,“家”),然后会收到以下异常:

Server Error in '/' Application. 
The controller for path '/Home' was not found or does not implement IController. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The controller for path '/Home' was not found or does not implement IController. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[HttpException (0x80004005): The controller for path '/Home' was not found or does not implement IController.] 
    System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +683921 
    System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +89 
    Castle.Proxies.Invocations.IControllerFactory_CreateController.InvokeMethodOnTarget() +155 
    Castle.DynamicProxy.AbstractInvocation.Proceed() +116 
    Glimpse.Core.Extensibility.ExecutionTimer.Time(Action action) +85 
    Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context) +186 
    Castle.DynamicProxy.AbstractInvocation.Proceed() +604 
    Castle.Proxies.IControllerFactoryProxy.CreateController(RequestContext requestContext, String controllerName) +193 
    System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +305 
    System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +87 
    System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +41 

[HttpException (0x80004005): Execution of the child request failed. Please examine the InnerException for more information.] 
    System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +785832 
    System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3977 
    System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +275 
    System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +94 
    System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +700 
    System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +123 
    Panoptes.Ui.Web.Views.Home.Index.Execute() in c:\Dropbox\Energy Management System\Application\Panoptes\Panoptes.Ui.Web\obj\CodeGen\Views\Home\Index.cshtml:48 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280 
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126 
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +143 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +181 
    RazorGenerator.Mvc.PrecompiledMvcView.Render(ViewContext viewContext, TextWriter writer) +952 
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378 
    Castle.Proxies.AsyncControllerActionInvokerProxy.InvokeActionResult_callback(ControllerContext controllerContext, ActionResult actionResult) +21 
    Castle.DynamicProxy.AbstractInvocation.Proceed() +116 
    Glimpse.Core.Extensibility.ExecutionTimer.Time(Action action) +85 
    Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context) +186 
    Castle.DynamicProxy.AbstractInvocation.Proceed() +604 
    System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265 
    System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +838644 
    System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51 
    System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034 

鉴别控制如下所示:

public class AuthenticationController : Controller 
{ 
    private ILogService _logService; 
    private IEmailProvider _emailProvider; 
    private IMembershipProvider _membershipProvider; 
    private IAuthenticationProvider _authenicationProvider; 

    public AuthenticationController(ILogService logService, IEmailProvider emailProvider, IMembershipProvider membershipProvider, IAuthenticationProvider authenicationProvider) 
    { 
     _logService = logService; 
     _emailProvider = emailProvider; 
     _membershipProvider = membershipProvider; 
     _authenicationProvider = authenicationProvider; 
    } 

    [AllowAnonymous] 
    [HttpGet] 
    ////[OutputCache(Duration = 3600, VaryByParam = "none")] 
    public ActionResult Index() 
    { 
     return View(); 
    } 

    [AllowAnonymous] 
    [HttpPost] 
    [ValidateHttpAntiForgeryToken] 
    public ActionResult Login(LoginModel model, string returnUrl) 
    { 
     if (Request.IsAuthenticated) 
     { 
      return RedirectToAction("Index", "Home"); 
     } 

     if (ModelState.IsValid) 
     { 
      if (_membershipProvider.ValidateUser(model.Username, model.Password)) 
      { 
       _authenicationProvider.AuthenticateUser(model.Username); 
       ////this.HttpContext.User = new GenericPrincipal(new GenericIdentity(model.Username), null); 

       if (!string.IsNullOrEmpty(returnUrl)) 
       { 
        if (Url.IsLocalUrl(returnUrl)) 
        { 
         return Redirect(returnUrl); 
        } 
        else 
        { 
         _logService.Log(new SecurityException(string.Format("Open redirect to {0} detected (Username {1})", returnUrl, model.Username))); 
         return View("Index", model); 
        } 
       } 
       else 
       { 
        return RedirectToAction("Index", "Home"); 
       } 
      } 
      else 
      { 
       ModelState.AddModelError(string.Empty, Resources.Controller.View.Authentication.Index.IncorrectUsernamePassword); 
      } 
     } 

     return View("Index", model); 
    } 

    [AllowAnonymous] 
    [HttpPost] 
    [ValidateHttpAntiForgeryToken] 
    public ActionResult ForgotPassword(LoginModel model) 
    { 
     if (ModelState.IsValidField("Username")) 
     { 
      if (!_membershipProvider.EnablePasswordRetrieval) 
      { 
       throw new Exception(Resources.Controller.View.Authentication.Index.PasswordRetreivalNotAllowed); 
      } 

      IMembershipUser user = _membershipProvider.FindUsersByName(model.Username).FirstOrDefault(); 

      if (user != null) 
      { 
       try 
       { 
        _emailProvider.Send(ConfigurationHelper.GetSmtpSettings().Smtp.From, user.EmailAddress, Resources.Global.PasswordRecoveryEmailSubject, user.GeneratePasswordRetreivalEmail()); 
        ModelState.AddModelSuccess(Resources.Controller.View.Authentication.Index.PasswordSentViaEmail); 
       } 
       catch (Exception ex) 
       { 
        _logService.Log(ex); 
        ModelState.AddModelError(string.Empty, Resources.Controller.View.Authentication.Index.UnableToRetreivePassword); 
       } 
      } 
      else 
      { 
       ModelState.AddModelError(string.Empty, Resources.Controller.View.Authentication.Index.EmailAddressDoesNotExist); 
      } 
     } 

     ViewBag.ShowForgottenPasswordForm = "true"; 

     return View("Index", model); 
    } 

    [HttpGet] 
    public ActionResult Logout() 
    { 
     _authenicationProvider.Logout(); 
     ModelState.AddModelInformation(Resources.Controller.View.Authentication.Index.Logout); 
     return View("Index"); 
    } 
} 

我的HomeController如下所示:

public class HomeController : Controller 
{ 
    private IMembershipProvider _membershipProvider; 
    private IAuthenticationProvider _authenticationProvider; 

    public HomeController(IMembershipProvider membershipProvider, IAuthenticationProvider authenticationProvider) 
    { 
     _membershipProvider = membershipProvider; 
     _authenticationProvider = authenticationProvider; 
    } 

    public ActionResult Index() 
    { 
     return View(_membershipProvider.GetCurrentUser()); 
    } 
} 

见下面我RouteConfig:

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}", 
      defaults: new { controller = "Authentication", action = "Index" }); 
    } 
} 

RouteDebugger返回TRUE的路线{控制器}/{行动}和{*包罗万象}并确认AppRelativeCurrentExecutionFilePath为:〜/主页

我已经调试代码我可以成功调试并进入HomeController构造函数和Index操作方法。我也一直能够步入“〜/查看/主页/ Index.cshtml”但它抛出异常的代码行:

<span class="username">@Model.UserName</span> 

有趣的是,在我踏进这个代码,我可以添加“@ Model.UserName”到我的手表列表中,我可以看到对象及其属性,但由于某种原因,它在进入或通过这行代码时会引发异常。

如果调试器步入HomeController,Index操作方法和Index视图,那么为什么它突然抛出异常,无法找到路径“〜/ Home”的HomeController?

捕获的提琴手数据可以在下面的链接中找到:http://d-h.st/IqV

我用剃刀生成编译我的观点,我也用Ninject.Mvc来解决我的控制器。还值得一提的是我已清理并重新生成编译的视图,并且我的项目不包含任何注册区域。

任何想法的?这可能是简单的或明显的,但我是MVC的新手,正在阅读/学习。

感谢

+1

你可以显示路由和你的家庭控制器类的初始化? – 2013-05-08 15:55:46

+0

你可以发布HomeController的代码吗? – christiandev 2013-05-08 15:57:16

+0

在问题中添加缺少的信息,希望这是好的。 – Dungimon 2013-05-08 16:03:24

回答

6

所以,人们可以看到这个问题,在这里回答就是为什么它被抛出异常,我怎么固定它:

的异常被抛出,因为在HomeController的下面的代码行索引视图:

<a href="@Html.Action("Log Out","Logout", "Authentication")"><i class="icon-key"></i> Log Out</a> 

正如你可以看到它的传递错误的论点和“退出”正在传递的动作名称时INFACT这应该是“注销”。我把它纠正以下和它的工作:

<a href="@Html.Action("Logout", "Authentication")"><i class="icon-key"></i> Log Out</a> 

所以,如果你得到这个例外,像我不明白为什么那么请确保你检查你的代码的其余部分在您的视图,以确保它是正确的。在这种情况下,框架没有提供意义异常消息和堆栈跟踪。

相关问题