我有这个类WindsorControllerFactory
继承自DefaultControllerFactory
public class WindsorControllerFactory : DefaultControllerFactory
{
private readonly IKernel _container;
public WindsorControllerFactory(IKernel container)
{
_container = container;
}
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, System.Type controllerType)
{
if(controllerType == null)
{
throw new HttpException(404, "Controller not found.");
}
return _container.Resolve(controllerType) as IController;//exception here no controller found
}
}
在我的帐户控制器中,我有登录功能 [授权]
public class AccountController : Controller
{
//
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login()
{
return View();
}
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
// [ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model)
{
if(Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
RedirectToAction("Index", "Home");
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
}
当我运行应用程序时,该类http://localhost:58383/Account/Login
中出现错误WindsorControllerFactory
,说找不到控制器。知道为什么会这样吗?