1
votes

Is it possible to have two default landing page for authentication in ASP.Net MVC? One for a specific folder i.e. Pages for Admin and the other is for everything else?

This is the scenario. I have an application with an Admin portal where only administrators can access and the Main portal for any active users. I am using the default forms authentication for MVC with the root web.config configured as below:

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="240" defaultUrl="~/" slidingExpiration="true"/>
</authentication>

So every user will be redirected to Account/Login when not they are not authenticated. Now, I want to have a separate landing page (Admin/Login) for admin pages when admin user is not yet authenticated. All Admin pages are in a folder named Admin. So is there a way for me to configure the authentication in the web.config of that folder to default to Admin/Login instead of Account/Login?

Edit: The rules are simple. When a user tries to access any admin page i.e. Directly changing the URL, and they are not logged in, then I was hoping they would be redirected to Admin/Login, instead of Account/Login. We don't need to check for role since we are already restricting the controller to Admin Roles only.

Is it better to do this in an actionfilter instead?

1
What are the rules for when you redirect them to ~/Admin/Login? Do you want to redirect there when ANYONE tries to access a ~/Admin/<page> that isn't an Admin? - Erik Philips

1 Answers

0
votes

Unless there is a way for you to differentiate admin from regular user on page loading then no.. If it is the same IP address being logged from you could do it like that ... or if its linked over from another account such as google login ... where you could check the user name and redirect based on if its saved as an admin... You would have to have a way to distinguish before you re-routed