override Microsoft.AspNetCore.Authorization.AuthorizeAttribute
public class ClaimRequirementAttribute : TypeFilterAttribute
{
public ClaimRequirementAttribute(string claimType, string claimValue) : base(typeof(ClaimRequirementFilter))
{
Arguments = new object[] {new Claim(claimType, claimValue) };
}
}
public class ClaimRequirementFilter : IAuthorizationFilter
{
readonly Claim _claim;
public ClaimRequirementFilter(Claim claim)
{
_claim = claim;
}
public void OnAuthorization(AuthorizationFilterContext context)
{
var hasClaim = context.HttpContext.User.Claims.Any(c => c.Type == _claim.Type && c.Value == _claim.Value);
if (!hasClaim)
{
context.Result = new ForbidResult();
}
}
}
[Route("api/resource")]
public class MyController : Controller
{
[ClaimRequirement(MyClaimTypes.Permission, "CanReadResource")]
[HttpGet]
public IActionResult GetResource()
{
return Ok();
}
}
Also in C#:
- C# get all files in directory
- unity instantiate vector3
- visual c#
- POST http://localhost:5001/api/v1/identity/login 500 (Internal Server Error) LoginForm.jsx:39 Error: Request failed with status code 500 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad (xhr.js:61)
- unity detect any key
- comment envoyer un socket C#
- how do I attach a player with a navMeshAgent
- c# remove from list in foreach
- c# linq to get most recent item from IList
- c# capitalize first letter
- C# webclient immitate browser
- uncaught syntaxerror invalid or unexpected token unity webgl
- Unity C# make object face away
- how to store some variables on the device in unity
- initialise icollection c#
- find negative version of integer in c#
- How to set an expiry date on a program
- c# make string null
- c# counting lines
- check distance to gameobject
- math class C# exponents
- to list c#
- open tcp socket c#
- why is c# say ; expected