加载solutionStream时发生错误

时间:2019-05-30 17:17:27

标签: c# visual-studio-2017 iis-7 asp.net-web-api2 postman

正在尝试配置我的ASP.NET WebAPI2应用程序以在IIS 7.0中工作。当我在以管理员权限运行并使用IIS Express的VS-2017中运行该应用程序时,我没有收到该错误。但是,当我发布应用程序并在本地IIS中运行它时,出现错误“加载solutionStream时发生错误”。

Controller方法正在执行的工作是接受从PostMan上传的文件,读取其流,并将该流提供给第三方API,该API返回文件的内容。

        [HttpPost]
        [ValidateMimeMultipartContentFilter]
        [Route("GetLabelVariables")]
        public async Task<IHttpActionResult> GetLabelVariables()
        {
            ILabel lbl;

            var uploadPath = HttpContext.Current.Server.MapPath("~/App_Data");

            var multiPartMemoryStreamProvider = new MultipartFormDataStreamProvider(uploadPath);

            await Request.Content.ReadAsMultipartAsync(multiPartMemoryStreamProvider);

            // Get thefile
            var fileupload = multiPartMemoryStreamProvider.FileData.First();

            // Get the temp name and path that MultipartFormDataStreamProvider used to save the file as:
            var tempPath = fileupload.LocalFileName;

            // Now read the file's data from the temp location.
            var bytes = File.ReadAllBytes(tempPath);

            // Using a MemoryStream
            using (var stream = new MemoryStream(bytes))
            {
// To Get the stream and return a LabelFile out of the stream. 
// The code fails here in IIS but passes in VisualStudio IIS Express running
// in administrator mode.
// Am suspecting the IIS has a special way it receives HttpRequestMessages
                lbl = PrintEngineFactory.PrintEngine.OpenLabel(stream);
            }

            return Ok(lbl.Variables.Select(x => new
                {
                    x.Name,
                    x.Description,
                    x.Length,
                    x.IsFixedLength
                }));
        }

enter image description here

0 个答案:

没有答案