Custom Authorization Attribute
Date : March 29 2020, 07:55 AM
like below fixes the issue I am implementing a CustomAuthorizeAttribute. I need to get the name of the action being executed. How can i get the name of current action name getting executed in the AuthorizeCore function which i am overriding ? , You can get the Action Name like this: public class CustomAuthFilter : IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
filterContext.ActionDescriptor.ActionName;
}
}
public class CustomAuthAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
}
}
|
Creating my custom security role and custom user group tables, to implement custom authorization for my asp.net mvc web
Date : March 29 2020, 07:55 AM
I hope this helps . If the ability exists to maintain the active domain groups there is no reason to maintain a local groups table isinrole can be used for group access checks
|
getting Roles that already set to custom Authorization attribute?
Date : March 29 2020, 07:55 AM
To fix the issue you can do by default it inhirits the Roles property from the base Authorize class so you can get the roles directly by using the Roles property For Example if (HttpContext.Current.User.Identity.IsAuthenticated && HttpContext.Current.User.IsInRole(Roles))
{
return true;
}
|
Custom Authorization attribute asp.net core
Date : March 29 2020, 07:55 AM
To fix this issue Using policies for something like this isn't overkill. You need a requirement: public class WhitelistRequirement: IAuthorizationRequirement
{
}
public class WhitelistHandler : AuthorizationHandler<WhitelistRequirement>
{
// Implement a constructor to inject dependencies, such as your whitelist
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
WhitelistRequirement requirement)
{
if (isInWhitelist) // Your implementation here
{
context.Succeed(requirement);
}
return Task.CompletedTask;
}
}
services.AddAuthorization(options =>
options.AddPolicy("WhitelistPolicy",
b => b.AddRequirements(new WhitelistRequirement())));
services.AddSingleton<IAuthorizationHandler, WhitelistHandler>();
[Authorize(Policy = "WhitelistPolicy")]
services.AddMvc(config =>
{
var policy = new AuthorizationPolicyBuilder()
.AddRequirements(new WhitelistRequirement())
.Build();
config.Filters.Add(new AuthorizeFilter(policy));
})
|
Custom authorization attribute in .NET Core
Tag : chash , By : user183345
Date : March 29 2020, 07:55 AM
|