Azure Functions | C#

Abhay Chandramouli 1,056 Reputation points
2023-07-12T04:13:17.3+00:00

Hi

I am using a c# azure function app. I need to send a response header named "Content-sys" with value "sys" .

Please let me know how to do it.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Developer technologies ASP.NET ASP.NET Core
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2023-07-12T06:52:25.84+00:00

    @Abhay Chandramouli Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I understand that you want to add custom response header to your C# Function App response.

    Here is the sample code which you can leverage. I was able to add the Content-sys: sys response header. See below:

    User's image

    Sample Code:

    #r "Newtonsoft.Json"
    
    using System.Net;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;
    
    public static async Task<HttpResponseMessage> Run(HttpRequest req, ILogger log)
    {   
        log.LogInformation("C# HTTP trigger function processed a request.");
    
        string responseMessage = "Hello, World!";
        var response = new HttpResponseMessage(HttpStatusCode.OK);
        response.Content = new StringContent(responseMessage);
    
        // Add custom header to the response
        response.Headers.Add("Content-sys", "sys");
    
        return response;
    }
    

    Hope this helps.

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.