NETFramework file response flow problem when turning to core

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.