0

I've inherited an ASP.NET MVC 3 application. I know NOTHING about MVC 3. I've been using ASP.NET Web Forms though for 5+ years. When I attempt to launch the application from Visual Studio, I receive a 404. The browser points to http://localhost/Account/Logon. I've noticed that in my project, there is:

  • /Controllers/AccountController.cs
  • /Views/Account/LogOn.cshtml

I am assuming this is what should be launched.I've set a breakpoint in the Global.asax.cs and found that I am being redirected to this page via the following event:

void WSFederationAuthenticationModule_AuthorizationFailed(object sender, AuthorizationFailedEventArgs e)
{
  e.RedirectToIdentityProvider = false;
  HttpContext.Response.Redirect("/Account/Logon");
}

When I launch the application, I get a 404. I'm completely lost in regards to how to resolve this. I also don't know how to "Set as Start Page" in the MVC world. Can somebody please help me get over this hurdle? I just want to run the application. Thank you so VERY VERY much!

Phone Developer
  • 1,411
  • 4
  • 25
  • 36
  • This is probably a daft question, but do you have MVC3 installed on your dev box? – Simon Nov 17 '11 at 14:28
  • scratch that, you probably wouldn't be able to build the app if you didn't. see, told you it was daft! – Simon Nov 17 '11 at 14:28
  • Here's where I found my answer: http://stackoverflow.com/questions/3877339/asp-net-mvc-beta-authorize-attribute-sends-me-to-wrong-action – Rafael Emshoff Oct 29 '12 at 08:25

2 Answers2

2

If you call

http://localhost/Account/Logon

MVC, if you changed no routes in global.asax, is looking for

  • a Controller Named "Account"

  • the method "LogOn" in this Controller.

If you ActionMethod "Account.LogOn" returns a View, MVC looks into the Views/Account/ Directory and try to find you LogOn View.

Lots of more informations:

Asp.NET MVC

Phil Haack´s Blog

Scott Guthrie´s Blog

Hope this helps

dknaack
  • 60,192
  • 27
  • 155
  • 202
  • Hi dknaack, I noticed there is a method that looks like public ActionResult LogOn() { return View("LogOn"); } This method is in a file located at /Controllers/AccountController.cs. So I'm very confused why I'm getting a 404. Any ideas? – Phone Developer Nov 17 '11 at 13:25
  • Right, methods in controllers are "actionMethods", they must return ActionResult or a derived type. Do you have the Views/Account folder and a LogOn file in there ? – dknaack Nov 17 '11 at 13:27
  • I have a Views/Account folder. That folder contains a file named LogOn.cshtml. – Phone Developer Nov 17 '11 at 14:12
1

I am assuming this is what should be launched

No, your assumption is wrong. In ASP.NET MVC you never access view directly. You always pass through a controller action which performs some processing on the model and returns a view.

So when you request /Account/Logon (assuming default routing) it is the Logon action on the AccountController that should be executed:

public class AccountController: Controller
{
    public ActionResult Logon()
    {
        ...
    }
}

If such action or controller doesn't exist in the project you would get 404.

Before proceeding any further with the inherited project I would very strongly recommend you familiarizing yourself with the basics of ASP.NET MVC by following some of the tutorials here: http://asp.net/mvc

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928