views:

265

answers:

2

Hi all,

I've recently created an ASP.NET MVC 2 application, which works perfectly in the development environment. However, when I deploy it to the server (123-reg Premium Hosting), I can access all of the expected areas - except the Account controller (www.host.info/Account). This then attempts to redirect to the Error.aspx page (www.host.info/Shared/Error.aspx) which it cannot find. I've checked that all of the views have been published, and they're all in the correct place.

It seems bizarre that two other controllers can be accessed with no problems, whereas the Account controller cannot be found. I have since renamed the AccountController to SecureController, and all of the dependencies, to no avail.

The problem with not being able to find the Error.aspx page also occurs on the development environment.

Any ideas would be greatly appreciated.

Thanks,

Chris

A: 

1) Can you check the DLL that was published to make sure that type exists in the assembly? Are any special modifiers applied to the Account controller compared to the other controllers (such as specific attributes, base classes, additional code)?

2) Can you verify what HttpMethod you are using to request the page? I'm assuming just a normal GET, but it may be coming in as a different verb causing you not to find your action method.

3) Are you using any custom routing, or just the standard {controller}/{action}/{id} setup?

Tejs
Thanks for the reply, I'm using just a normal Http GET, and just the standard routing. How would you recommend inspecting the DLL?
Chris
OK, so I've just inspected the DLL using .NET Reflector, and found that the Account controller has been compiled and added to the DLL. Nothing special has been done to this particular controller, so I have no idea why it's not being found properly!
Chris
Can you post your AccountController code VS a working controller? Have you verified there are no Typos? Are there different IIS versions between dev and prod?
Tejs
A: 

The version of IIS on the server is 7.0, of which I have no control over.

The account controller code all works perfectly on the development environment, and the code is as follows:

[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();
    }

}
Chris
I don't see an Index() action method - if you are requesting site.info/Account/, then no Action method exists to handle your request.
Tejs
Sorry, I should have mentioned it earlier in the post - I'm attempting to request site.info/Account/LogOn or in this context - site.info/Secure/LogOn. Thinking about it, I'll try adding an Index action and view, then see what happens on the server.
Chris