简体   繁体   English

登录后根据那里的角色重定向到特定区域的用户

[英]Redirect to user on specific area after login based on there role

i am creating web application using dot.net core 6.0.我正在使用 dot.net core 6.0 创建 web 应用程序。 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!我认为这可以帮助你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 登录后将用户重定向到特定页面 - Redirect user to a specific page after login 登录后 MVC Core 5 将用户重定向到在区域中查看 - MVC Core 5 Redirect user to View in Area after login Asp.net Identity 2.0-根据登录时的角色重定向外部认证的用户 - Asp.net Identity 2.0 - redirect externally authenticated user based on role at login 根据ASP.NET MVC 4 Internet应用程序登录中的用户角色重定向到其他页面 - redirect to different pages based on user role in ASP.NET MVC 4 Internet Application Login 登录后如何使用asp.net中的角色管理重定向用户? - How to redirect user after login using role management in asp.net? 登录后,用户根据asp.net中的角色重定向其他页面 - After Login User redirect different Page according to Role In asp.net 管理员用户无法登录(基于角色) - Admin user not able to login (Role based) 登录后,我应该在帐户控制器的哪个位置检查用户是否具有特定角色? - Where exactly in the account controller should I check if a user is in a specific role after login? 如果用户登陆受保护页面,那么如何根据用户角色进行重定向? - If user lands on protected page then how to redirect based on user role? 自定义角色提供程序不起作用-登录后立即重定向到登录页面 - Custom Role Provider not working - Instant redirect to login page after logging in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM