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.