Click here to Skip to main content
15,563,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to autorize in controller action via RedirectingAction class.
When I call this class above the Home/Privacy, I just want to enter the type and value of the claim to check, but I do not set the IHttpContextAccessor object.
i want set value this via dependency injection.
In this case, the value is null

in home controller:

[RedirectingAction("heivooon", "kahoo")]

       public IActionResult Privacy()
           return View();

in RedirectingAction :
public class RedirectingActionAttribute : ActionFilterAttribute
       private string _claimTypee; private string _claimValuee; IAuthorizationService _authorization; IHttpContextAccessor _HttpContextAccessor;

       public RedirectingActionAttribute(string claimTypee, string claimValuee)
           _claimTypee = claimTypee; _claimValuee = claimValuee;

       public RedirectingActionAttribute(IAuthorizationService authorization, IHttpContextAccessor HttpContextAccessor)
           _authorization = authorization; _HttpContextAccessor = HttpContextAccessor;
       public override void OnActionExecuting(ActionExecutingContext filterContext)

           //if (someConditionIsMet)
           string username = _HttpContextAccessor.HttpContext.User.Claims.FirstOrDefault(c => c.Type == "unique_name")?.Value;
           AuthenticationController.Policy p = new AuthenticationController.Policy();
           p.type = _claimTypee; p.value = _claimValuee; p.userName = username; p.acionAndControl = "Home/Privacy";
           filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
               controllerr = "Authentication",
               action = "Authorize"

What I have tried:

Please help me how to set value the IHttpContextAccessor object as dependency injection?
Updated 19-Dec-20 19:13pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900