I have simple custom authentication filter:
public class MyAuthAttribute : FilterAttribute, IAuthenticationFilter
{
public void OnAuthentication(AuthenticationContext filterContext)
{
filterContext.Result = new RedirectResult("Account/Login");
}
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
//throw new NotImplementedException();
}
}
There are also HomeController with Index action method and AccountController with Login action method. The Index action method uses my custom filter. When I try to call Index action method, my filter intercepts code execution and make redirect to Home/Account/Login url. Why does it happen? I expected a call of Login action in AccountController.
This happens because of the way you have given the URL i.e.
"Account/Login"
. When you do not start the URL with"/"
, it will check for theaction method
in the current controller. To redirect to the correct controller and method use -"/APPLICATION_NAME/CONTROLLER_NAME/METHOD_NAME"