[英]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.