I'm creating a custom attribute in dotnet that is supposed to check the authorization header. If it is the same as some hard coded string it is supposed to pass but else the user should not be able to use the specified route.
I think I'm getting the response header correctly but I'm not sure how to send a HTTP response if it fails.
public class CustomAuthorization : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext context) { var httpContext = context.HttpContext; string authHeader = httpContext.Request.Headers["Authorization"]; if(authHeader == "Kawaii") { return; //do nothing cause its fine } else { httpContext.Response.WriteAsync("The authorization header was incorrect, is should be Kawaii"); } } } Any help would be greatly appreciated!