Download ASP.NET Web API

I have a WebAPI controller that needs to download some files depending on the request, but when it comes to simple text files, it does not give me a request to download a browser. This gives me a simple text answer such as JSON (in my case it is JSONP WebAPI ).

I checked other Q&A from the stack (and other sites), but I still haven't received anything:

Here it outputs my current code:

var httpResponse = new HttpResponseMessage(HttpStatusCode.OK);
httpResponse.Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(content)));
httpResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
httpResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
httpResponse.Content.Headers.ContentDisposition.FileName = "speedcam.txt";
return httpResponse;

And this is the answer of Chrome:

Cache-Control: no cache

Content-Disposition: mounts; file name = speedcam.txt

Content-Length: 17462

Content-Type: application / octet stream

: , 27 2012 04:53:23 GMT

Expires: -1

Pragma:

: Microsoft-IIS/8.0

X- -: 4.0.30319

X-Powered-By: ASP.NET

X :??? = UTF-8 TTpcVHJhYmFsaG9cTWFwYVJhZGFyXE1hcGFSYWRhci5XZWJBUEk0XEV4cG9ydGE =

, , "" Chrome Dev Tools.

+5
3

, ;

httpResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
0

Check mime extension in web.config / IIS

0
source

All Articles