Question

I believe this is fairly simple. I have a small site for database management for a customer. When the user logs in, I want to reroute them to either the admin screen or to the user screen, based on their role. Currently it sends them to the Home screen.

Can I use Roles.IsUserInRole() in the RouteConfig? I tried a few things but it's not liking it. What's easiest way to reroute based on Role? My RouteConfig is simply:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new 
            { 
               controller = "Home",
               action = "Index",
               id = UrlParameter.Optional
            }
       );
   }
Was it helpful?

Solution

I think it's just fine to do this check in the Index action of the HomeController and use RedirectToAction to send the user to the right page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top