1

Как определить начальную страницу в зависимости от роли пользователя?

Что бы с одними ролями

 [Authorize(Roles = "Agent, SuperVizer")]
    public async Task<IActionResult> Index()

шли сюда, а с другими

[Authorize(Roles = "Ispolnitel")]
    public async Task<IActionResult> IndexIspolnitel()

сюда.

Как я понимаю, роутинг определен в Startup.cs но как изменить его что бы он учитывал роль.

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

1 ответ 1

0

Сделал, так не уверен что совсем правильно но работает.

        [Authorize]
        public async Task<IActionResult> Index()
        {
            if (HttpContext.User.IsInRole("Ispolnitel"))
            {
                return Redirect("/Home/IndexIspolnitel");
            }


            if (HttpContext.User.IsInRole("AGENT") || HttpContext.User.IsInRole("SuperVizer"))
            {
                return Redirect("/Home/IndexAgent");
            }                
            return View();
        }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.