I have a background in desktop software development and am getting started with learning ASP.NET MVC.
In my default HomeController I have the Index action which has code that looks like this:
if (!Request.IsAuthenticated)
return RedirectToAction("Login", "Account");
In other words, redirect the user to "/account/login". The AccountController.Login action will then handle the user and send him back to the HomeController once he logs in successfully.
This code smells to me, perhaps just because I'm accustomed to doing things differently in desktop software. What if I change the name of the Login action to "LogOn"? What if I remove the AccountController altogether and replace it with something else? I will introduce a new bug but I won't get compiler errors, and my unit tests probably won't catch it either. Since I used strings to specify controller and action names, refactoring and redesigning has more potential to break code all over the place.
What I would like is something like this:
if (!Request.IsAuthenticated)
return RedirectToAction(() => AccountController.Login);
However I'm not sure if that's even possible or if it's the best way to do it.
Am I being stupid, or have other people had the same problem? What do you do to get around it?