0

I have a web service written in .NET where the controller methods look like this:

[Route("upload/")]
    [HttpPost]
    public async Task<ApiResponse<Form12_Attachement>> UploadFile()
    {

    }

The objects called ApiResponse and Form12_Attachment are custom classes written by me and containing a few string members.

I need to add a custom header to the response (namely, allow cross-site scripting with Access-Control-Allow-Origin).

I know how to add a custom header to the webservice when it returns a System.Net.Request type object:

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
  System.Net.WebRequest request = base.GetWebRequest(uri);
  request.Headers.Add("myheader", "myheader_value");
  return request;
}

However, my web service returns a custom class. In this case, how can I add custom headers to the response?

Here's a solution that I found: add this into the WebApiConfig.Register() but it didn't work:

        config.EnableCors();

It doesn't work because my HttpConfiguration object doesn't have the EnableCors method.

2
  • 1
    Did you try that stackoverflow.com/questions/23746034/… ? Commented Dec 19, 2016 at 8:26
  • Thanks! I've marked my question as a duplicate. Commented Dec 19, 2016 at 8:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.