It is not appropriate to use redirect inside AuthorizeAttribute because it is supposed only to check Authorize and return results,and also it may have redirected after checking Authorization. why you don't use: the action filter attribute for more instances: https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/understanding-action-filters-cs
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToString();
string actionName = filterContext.ActionDescriptor.ActionName.ToString();
//Authentication & Authorization mechanism
//if fail then I want to redirect to login Controller with parameter '1'
//I have tried the following methods, both redirects but not pasasing the parameter
//I have tried the following methods, both redirects but not passing the parameter
//Method 1
var values = new RouteValueDictionary(new {
action = "Index",
controller = "Login",
code = "1"
});
filterContext.Result = new RedirectToRouteResult(values);
//Method 2 also tried Login/Index?code=1
filterContext.Result = new RedirectResult("Login/Index/1");
}