ASP.NET MVC 2 - 找不到帐户控制器

时间:2010-05-01 14:11:14

标签: c# asp.net-mvc asp.net-mvc-routing

我最近创建了一个ASP.NET MVC 2应用程序,它在开发环境中运行良好。但是,当我将其部署到服务器(123-reg Premium Hosting)时,我可以访问所有预期的区域 - 除了帐户控制器(www.host.info/Account)。然后尝试重定向到找不到的Error.aspx页面(www.host.info/Shared/Error.aspx)。我已经检查过所有的观点都已发布,而且它们都在正确的位置。

似乎奇怪的是,可以毫无问题地访问其他两个控制器,但找不到帐户控制器。我已经将AccountController重命名为SecureController,并且所有依赖项都没有用。

在开发环境中也会出现无法找到Error.aspx页面的问题。

非常感谢任何想法。

谢谢,

克里斯

2 个答案:

答案 0 :(得分:0)

1)您是否可以检查已发布的DLL以确保程序集中存在该类型?与其他控制器相比,是否将任何特殊修饰符应用于Account控制器(例如特定属性,基类,附加代码)?

2)你能验证你用来请求页面的HttpMethod吗?我假设只是一个正常的GET,但它可能是一个不同的动词,导致你找不到你的行动方法。

3)您使用的是自定义路由,还是仅使用标准{controller}/{action}/{id}设置?

答案 1 :(得分:0)

服务器上的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();
    }

}