In my code, I am calling a function, which does some validation checks against the database and if they fail, it should send the user to the "Access Denied" page ... but doesn't seem to work.
Previously, the redirect would been with Server.Transfer or Response.Redirect, but not sure how you achieve the correct effect, with MVC.
Simplified, my code looks like this and any help would be appreciated
private void CheckSecruity()
{
// secruity checks here
if (failCheck)
RedirectToAction("NoAccess", "MyController");
// if code gets here, security was passed
}
public ActionResult MyPage()
{
// Call Security Function
CheckSecruity();
/*
Do normal code
*/
// Display page
return View();
}
When running the code drops into the CheckSecurity() function, but regardless of the code in there, it always shows MyPage
Your
RedirectToActionreturns aRedirectToRouteResult, so you should do something like: