Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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();
    }
}
Comment

ExecuteResultAsync ActionContext statuscode

return new ObjectResult("The message") { 
    StatusCode = (int?) HttpStatusCode.Unauthorized 
};
Comment

PREVIOUS NEXT
Code Example
Csharp :: revision1 
Csharp :: unity move in x seconds to pos 
Csharp :: unity call function after delay 
Csharp :: using randomly chars to build a string 
Csharp :: C# enum fglag 
Csharp :: C# if with obj params 
Csharp :: expander vertical wpf 
Csharp :: c# list to string replace last comma with and 
Csharp :: c# list.except compare classes with IEqualityComparer 
Csharp :: c# expression func automatically select return type 
Csharp :: process run teamviewer address parametr c# 
Csharp :: c# sprintf equivalent 
Csharp :: close windows by esc wpf 
Csharp :: skrivetænking 
Csharp :: runner dotnet trace inside docker container 
Csharp :: c# how to debig 
Csharp :: Web API - Stream large file to client 
Csharp :: gridview edit update delete in asp.net textbox size 
Csharp :: c# same folder path 
Csharp :: c# unhandled exception in thread” 
Csharp :: unity run all interfaces 
Csharp :: dapper execute with list of ids 
Csharp :: c# how to group console output into columns 
Csharp :: If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. 
Csharp :: distinct and not null c# 
Csharp :: DisplayUnitType revit 2022 
Csharp :: Set orientation of moving object towards it movement direction 
Csharp :: Runtime.getRuntime().addShutdownHook(printingHook); c# 
Csharp :: method declaration in c# 
Csharp :: conevrt list to pipe separated string c# 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =