Earlier I had similar issue.
I have created asp mvc default template project and set authorization attribute on home controller.
When I run app url is:
http://localhost:48403/Account/LogOn?ReturnUrl=%2f
what I try to get is just http://localhost:48403 when user is no authenticated but I just have no luck with reouting setup 🙁
I have tried to put this in global.asax but no luck:
routes.MapRoute("Login", "",
new { controller = "Account", action = "LogOn" }
);
This is my whole global.asax
routes.MapRoute("About", "About",
new { controller = "Home", action = "About" }
);
routes.MapRoute("Login", "",
new { controller = "Account", action = "LogOn" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
You could write a custom Authorize attribute which instead if redirecting will directly render the LogOn view:
then decorate your HomeController with it:
then your AccountController does no longer need to worry about ReturnUrls:
and finally you will need to modify the action of the form in ~/Views/Account/LogOn.cshtml to point to the correct controller:
You could leave your routes by default: