ExecuteResultAsync ActionContext statuscode
return new ObjectResult("The message") {
StatusCode = (int?) HttpStatusCode.Unauthorized
};
ExecuteResultAsync ActionContext statuscode
return new ObjectResult("The message") {
StatusCode = (int?) HttpStatusCode.Unauthorized
};
ExecuteResultAsync ActionContext statuscode
public IActionResult IWillNotBeCalled()
{
return new UnauthorizedWithMessageResult("MY SQL ERROR");
}
public class UnauthorizedWithMessageResult : IActionResult
{
private readonly string _message;
public UnauthorizedWithMessageResult(string message)
{
_message = message;
}
public async Task ExecuteResultAsync(ActionContext context)
{
// you need to do this before setting the body content
context.HttpContext.Response.StatusCode = 403;
var myByteArray = Encoding.UTF8.GetBytes(_message);
await context.HttpContext.Response.Body.WriteAsync(myByteArray, 0, myByteArray.Length);
await context.HttpContext.Response.Body.FlushAsync();
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us