0

I am trying to to fetch image from server and display in my mobile using .net core API. and I use System.Web.Hosting.HostingEnvironment.MapPath(path) to map the path from server but it throw me an error System.Web.Hosting not include in System.Web how can fix this problem? pls help me.

And I try to add System.Web, i chage target framework from .net core 2.0.0 to .net core 2.2.0

using System.Threading.Tasks;
using BRT.API.Helpers;
using BRT.BLL.Model;
using BRT.BLL.Services;
using BRT.BLL.Services.Interfaces;
using BRT.DAL.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
//using System.Web.Hosting;
using System.Net;
using System.Net.Http;
 [AllowAnonymous]
        [HttpGet]
        [Route ("ReadConfirmationPhoto/{productSN}")]
        public async Task<HttpResponseMessage> ReadConfirmationPhoto (string productSN) {
            var result = await _service.ReadPhysicalFile (productSN);
             HttpRequestMessage request = new HttpRequestMessage();
             var response = request.CreateResponse(HttpStatusCode.OK);
             var path = result.FileName;
            path = System.Web.Hosting.HostingEnvironment.MapPath(path);
            var ext = System.IO.Path.GetExtension(path);
            var contents = System.IO.File.ReadAllBytes(path);
            System.IO.MemoryStream ms = new System.IO.MemoryStream(contents);
            response.Content = new StreamContent(ms);
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ext);
            return response;
}
daniel fitsum
  • 31
  • 1
  • 1
  • 3
  • Does this answer your question? [can't add reference to System.Web.Hosting](https://stackoverflow.com/questions/26236721/cant-add-reference-to-system-web-hosting) – Ian Kemp Jul 06 '20 at 12:00

1 Answers1

0

You need to use HostingEnvironment class instaed of Hosting.

You may refer to the post: can't add reference to System.Web.Hosting

Net Solver
  • 127
  • 1
  • 7