[英]ASP.NET MVC 4 Controller Fails No type was found that matches the controller named 'account'
[英]ASP.NET MVC 2 - Account controller not found
我最近創建了一個ASP.NET MVC 2應用程序,該應用程序在開發環境中運行良好。 但是,當我將其部署到服務器(123-reg高級托管)時,我可以訪問所有預期的區域-帳戶控制器(www.host.info/Account)除外。 然后,這將嘗試重定向到無法找到的Error.aspx頁面(www.host.info/Shared/Error.aspx)。 我檢查了所有視圖是否已發布,並將它們放在正確的位置。
可以毫無問題地訪問另外兩個控制器,而找不到帳戶控制器,這似乎很奇怪。 此后,我將AccountController重命名為SecureController,並將所有依賴項都重命名為無效。
在開發環境中也會出現無法找到Error.aspx頁的問題。
任何想法將不勝感激。
謝謝,
克里斯
1)您可以檢查發布的DLL,以確保程序集中存在該類型嗎? 與其他控制器相比,是否對帳戶控制器應用了任何特殊修飾符(例如特定屬性,基類,附加代碼)?
2)您可以驗證要使用什么HttpMethod來請求頁面嗎? 我假設只是一個普通的GET,但是它可能是作為另一個動詞出現的,導致您找不到自己的操作方法。
3)您使用的是任何自定義路由,還是僅使用標准的{controller}/{action}/{id}
設置?
服務器上的IIS版本是7.0,我無法控制。
帳戶控制器代碼都可以在開發環境上完美運行,其代碼如下:
[HandleError]
public class SecureController : Controller
{
private UserManager manager;
public IFormsAuthenticationService FormsService { get; set; }
public IMembershipService MembershipService { get; set; }
protected override void Initialize(RequestContext requestContext)
{
if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
base.Initialize(requestContext);
}
// Lazy man's Dependency Injection for now, use Ninject later!
public SecureController(UserManager mgr) { manager = mgr; }
public SecureController() : this(new UserManager(new PortfolioDataDataContext())) { }
// **************************************
// URL: /Account/LogOn
// **************************************
public ActionResult LogOn()
{
return View();
}
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
// **************************************
// URL: /Account/LogOff
// **************************************
public ActionResult LogOff()
{
FormsService.SignOut();
return RedirectToAction("Index", "Home");
}
// **************************************
// URL: /Account/Register
// **************************************
public ActionResult Register()
{
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View();
}
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus = manager.CreateUser(model.UserName, model.Password, model.Email, model.FullName);
if (createStatus == MembershipCreateStatus.Success)
{
FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View(model);
}
// **************************************
// URL: /Account/ChangePassword
// **************************************
[Authorize]
public ActionResult ChangePassword()
{
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View();
}
[Authorize]
[HttpPost]
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
{
return RedirectToAction("ChangePasswordSuccess");
}
else
{
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
}
}
// If we got this far, something failed, redisplay form
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View(model);
}
// **************************************
// URL: /Account/ChangePasswordSuccess
// **************************************
public ActionResult ChangePasswordSuccess()
{
return View();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.