繁体   English   中英

如何修复System.web中未包含的System.Web.Hosting

[英]how to fix System.Web.Hosting not include in system.web

我正在尝试从服务器获取图像并使用.net核心API在我的手机中显示。 并且我使用System.Web.Hosting.HostingEnvironment.MapPath(path)映射来自服务器的路径,但它抛出一个错误System.Web.Hosting,未包含在System.Web中,如何解决此问题? 请帮助我。

我尝试添加System.Web,将目标框架从.net core 2.0.0扩展到.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;
}

您需要使用HostingEnvironment类代替Hosting。

您可以参考该帖子: 无法添加对System.Web.Hosting的引用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM