asp.net mvc - The controller for path '/Home' was not found or does not implement IController -
i've searched internet high , low , checked answered questions same title , cannot figure 1 out.
i return redirecttoaction("index", "home") action method in authentication controller , receive following exception:
server error in '/' application. controller path '/home' not found or not implement icontroller. description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code. exception details: system.web.httpexception: controller path '/home' not found or not implement icontroller. source error: unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below. stack trace: [httpexception (0x80004005): controller path '/home' not found or 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 child request failed. please examine innerexception 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
the authentication controller looks follows:
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 {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"); } }
my homecontroller looks follows:
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()); } }
see below 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 returns true routes {controller}/{action} , {*catchall} , confirms apprelativecurrentexecutionfilepath as: ~/home
i have debugged code , can debug , step homecontroller constructor , index action method. have been able step "~/views/home/index.cshtml" throws exception @ line of code:
<span class="username">@model.username</span>
funnily enough, before step code can add "@model.username" list of watches , can see object , properties fine, reason throws exception when stepping or on line of code.
if debugger steps homecontroller, index action method , index view, why of sudden throwing exception can't find homecontroller path "~/home"?
the captured fiddler data can found @ following link: http://d-h.st/iqv
i have used razor generator compile views , using ninject.mvc resolve controllers. it's worth mentioning have cleared down , re-generated compiled views , project not contain registered areas.
any idea's? might simple or obvious 1 i'm new mvc , reading/learning go.
thanks
so people can see question answered here why throwing exception , how fixed it:
the exception being thrown because of following line of code in homecontroller index view:
<a href="@html.action("log out","logout", "authentication")"><i class="icon-key"></i> log out</a>
as can see it's passing wrong arguments , "log out" being passed in action name when infact should "logout". correct following , worked:
<a href="@html.action("logout", "authentication")"><i class="icon-key"></i> log out</a>
so if you're getting exception , me can't understand why please make sure check rest of code in view make sure correct. in instance framework doesn't provide meaning exception message , stacktrace.
Comments
Post a Comment