I have LoginController which contains the following Action. Index Action takes optional paramter.
public ActionResult Index(string code = "")
{
if (code == "1")
{
ViewBag.Message = "Please Login First";
}
else {
ViewBag.Message = "Welcome to Login Page.";
}
return View();
}
I have my own authentication filter which contains the following code
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");
}