L
L
llexus2016-10-28 14:37:43
ASP.NET
llexus, 2016-10-28 14:37:43

Is it possible to make a redirect before routing in Asp.Net Core?

Hello. I'm just starting to learn web development on aspe. And I immediately ran into a problem that I can not solve. The essence is as follows:
If the user has not filled out his profile after registration, then you need to redirect him from all pages to the filling page. Why not add a check in every controller method? You can also add a redirect directly to Login() itself, but it is called only once, and when the user already has cookies, it is not at all clear where they are checked.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
llexus, 2016-10-28
@llexus

Петр Да, то что надо! Запилил базовый класс и от него наследовал остальные.

public class BaseController : Controller
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);

            if (redirect)
                context.Result = new RedirectResult(Url.Action("Action", "Controller"));
        }
    }

Петр, 2016-10-28
@petermzg

Asp.Net Identity + атрибут [Authorize], который можно выставить для класса контроллера

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question