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
Many thanks to Stijn for that direction; have investigated that and it's perfect! I thought that I would share the outcome of what I have done, as it varies slightly from using the MVC Role...
I added the FILTERS folder and a new (SecurityAttribute.cs) class in that folder, which contains the following code (apologies, I have to cut some out).
I have no doubt that the code can be improved, which is what I will continue to work on, but this is certainly a starter.