简体   繁体   中英

Redirect to user on specific area after login based on there role

i am creating web application using dot.net core 6.0. application contain two type of user one is admin and second is simple user area. i want that when user is login base on there role he/she redirect to there area like if user is admin he redirect to admin area. else redirect to user area. `

@if (signInManager.IsSignedIn(User))
 {
 if (User.IsInRole("SuperAdmin"))
 {
 Response.Redirect(Url.Action("Index", "AdminDashboard", new { Area = "SuperAdmin" }));
}
else if (User.IsInRole("User"))
{
Response.Redirect(Url.Action("Index", "User", new { Area = "User" }));
}
}

` i try this code in layout file but this code in not work properly

try this methods

@if (signInManager.IsSignedIn(User))
{
var user =await    userManager.FindByNameAsync(Input.Email);
var roles = await  userManager.GetRolesAsync(user);
if (roles.Contains("SuperAdmin"))
 {
 Response.Redirect(Url.Action("Index", "AdminDashboard", new { Area = 
 "SuperAdmin" }));
 }
}

I think this can help you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM