MVC: Conditional Redirect to View

Please see my other MVC article.

Redirecting Users to a New Page Based on IF Logic

Similar to the article (link) MVC: Conditionally Display View link, this article illustrates how to use condition logic to change the user experience by using the controller’s default function to test if the current user is part of the Administrator role, and if so, a custom function to load a dropdown, otherwise, the user is redirected back to the homepage.
This can be a helpful deterrent to users directly accessing pages via the URL when they are not authorized to do so.
1.MVC-Conditional-Redirect-to-View

The IF statement uses my custom IsUserAdmin() function passing in the user’s current web identity provided by the browser – in this case, Internet Explorer.
The IsUserAdmin() function receives the user’s identity, strips the domain, then uses a Linq query to test the user’s identity in the Admins table.
If any records are returned, the test passes.

2.MVC-Conditional-Redirect-to-View

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s