0
devmahmod created
i have user in role ContentManager i want when user login redirect to ManagerRequests how to solve , I'm using mvc core razor
3 Answer(s)
-
1
hi
You can add the redirect code in the Index page. This is easiest
public ActionResult Index() { if (CurrentUser.IsAuthenticated && CurrentUser.Roles.Contains("ContentManager")) { return Redirect("~/ManagerRequests"); } return Page(); }
You can also do it in the
OnSignedIn
method.context.Services.ConfigureApplicationCookie(options => { var previousOnSignedIn = options.Events.OnSignedIn; options.Events.OnSignedIn = async cookieSignedInContext => { await previousOnSignedIn(cookieSignedInContext); var currentUser = cookieSignedInContext.HttpContext.RequestServices.GetRequiredService<ICurrentUser>(); if (currentUser.IsAuthenticated && currentUser.Roles.Contains("ContentManager")) { cookieSignedInContext.HttpContext.Response.Redirect("api/account/authenticator-info"); } }; }); }
-
0
Thanks for you answer which worked for me first solution which in index page
public class IndexModel : SCISPPageModel { public IActionResult OnGet() { if (!CurrentUser.IsAuthenticated) { return Page(); } // Redirect based on role priority (Manager > Creator) var roleRedirectMap = new Dictionary<string, string> { { ApplicationRoles.ContentManager.ToString(), "~/ManagerRequests" }, //{ ApplicationRoles.ContentCreator.ToString(), "~/CreatorRequests" } }; foreach (var role in roleRedirectMap.Keys) { if (CurrentUser.Roles.Contains(role, StringComparer.OrdinalIgnoreCase)) { return Redirect(roleRedirectMap[role]); } } // If authenticated but no matching role return Page(); } }
-
0
Great!