When the framework Webapi project was transferred to the WEBAPI project on the Netcore platform, it was found that the original return file response stream was invalidated under the Netcore platform. The code below returns the PDF file response stream for the front-end display
/// <summary> ///get a preview PDF based on the preview ID of the PDF/// </summary> /// <param name= "Id" ></param> /// <returns></returns>[HttpGet] [Route ("getpreviewpdf")] Publichttpresponsemessage getpreviewpdf (Guid Id) {stringpdfbase64string = _cachemanager.get<string>(Id.tostring ()); varResponse =NewHttpresponsemessage (); if(!string. IsNullOrEmpty (pdfbase64string)) {byte[] Pdfarray =convert.frombase64string (pdfbase64string); Response. StatusCode=System.Net.HttpStatusCode.OK; Response. Content=Newbytearraycontent (Pdfarray); Response. Content.Headers.ContentType=Mediatypeheadervalue.parse (mimetypes.applicationpdf); } Else{Response. StatusCode=System.Net.HttpStatusCode.Gone; } returnresponse; }
Do not remember the reference URL, anyway, is stackoverflow above. Features that support legacy MVC need to be configured in the Netcore project.
1. Add a NuGet reference
2. Add the configuration in the Startup class
Public IServiceProvider configureservices (iservicecollection services) { services. Addmvc (). Addwebapiconventions ();}
NETFramework file response flow problem when turning to core