我的 ASP.NET MVC 构建的应用程序未从用户读取文件

发布于 2025-01-09 02:29:25 字数 2930 浏览 0 评论 0原文

问题在于上传到本地网络 IIS 上的构建 ASP.NET MVC 解决方案。 当我尝试从主机以外的其他设备上传文件时,目标页面未加载。 当我尝试从主机上传文件时,正在加载没有文件数据的页面。 当我在电脑上的 Visual Studio 中运行它时,一切正常。当我尝试在 Windows Server 上运行构建的解决方案时,出现了问题。

我应该怎么办?是IIS设置问题还是代码错误?

private void ReadFileFromStream(DateChoice datechoice, DateTime dateStartobj, DateTime dateEndobj, string FirstParameter_name, string SecondParameter_name, string ThirdParameter_name, string FourthParameter_name, string FivethParameter_name)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                datechoice.File.InputStream.CopyTo(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                using (var streamReader = new StreamReader(memoryStream))
                {
                    var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
                    {
                        Delimiter = ";",
                        HasHeaderRecord = false
                    };

                    ReadCSV(dateStartobj, dateEndobj, streamReader, csvConfig, FirstParameter_name, SecondParameter_name, ThirdParameter_name, FourthParameter_name, FivethParameter_name);
                }
            }
        }

 private void ReadCSV(DateTime dateStartobj, DateTime dateEndobj, StreamReader streamReader, CsvConfiguration csvConfig, string FirstParameter_name, string SecondParameter_name, string ThirdParameter_name, string FourthParameter_name, string FivethParameter_name)
        {
            using (var csvReader = new CsvReader(streamReader, csvConfig))
            {
                var records = csvReader.GetRecords<Read>().ToList();
                List<DataPoint> Parametry_A, Parametry_B, Parametry_C, Parametry_D, Parametry_E;
                NewListDeclarate(out Parametry_A, out Parametry_B, out Parametry_C, out Parametry_D, out Parametry_E);
                foreach (var record in records)
                {
                    if (DateVerification(record))
                    {
                        DateTime label_date;
                        DataPoint dataPointA, dataPointB, dataPointC, dataPointD, dataPointE;
                        NewPointsGenerate(record, out label_date, out dataPointA, out dataPointB, out dataPointC, out dataPointD, out dataPointE, FirstParameter_name, SecondParameter_name, ThirdParameter_name, FourthParameter_name, FivethParameter_name);
                        if (UserDateCheck(dateStartobj, dateEndobj, label_date))
                        {
                            AddPointsToList(Parametry_A, Parametry_B, Parametry_C, Parametry_D, Parametry_E, dataPointA, dataPointB, dataPointC, dataPointD, dataPointE);
                        }
                    }
                }
                ReturnListsToViewBag(Parametry_A, Parametry_B, Parametry_C, Parametry_D, Parametry_E);
            }
        }

The problem is with built ASP.NET MVC solution uploaded on IIS in local network.
When I'm trying to upload file from other device than host, the target page is not loading.
When I'm trying to upload file from host is loading page without data from files.
All works fine when i'm running it in Visual Studio on my pc. The problem was made when i tried to run built solution o Windows Server.

What should I do? It is problem with IIS settings or with wrong code?

private void ReadFileFromStream(DateChoice datechoice, DateTime dateStartobj, DateTime dateEndobj, string FirstParameter_name, string SecondParameter_name, string ThirdParameter_name, string FourthParameter_name, string FivethParameter_name)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                datechoice.File.InputStream.CopyTo(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                using (var streamReader = new StreamReader(memoryStream))
                {
                    var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
                    {
                        Delimiter = ";",
                        HasHeaderRecord = false
                    };

                    ReadCSV(dateStartobj, dateEndobj, streamReader, csvConfig, FirstParameter_name, SecondParameter_name, ThirdParameter_name, FourthParameter_name, FivethParameter_name);
                }
            }
        }

 private void ReadCSV(DateTime dateStartobj, DateTime dateEndobj, StreamReader streamReader, CsvConfiguration csvConfig, string FirstParameter_name, string SecondParameter_name, string ThirdParameter_name, string FourthParameter_name, string FivethParameter_name)
        {
            using (var csvReader = new CsvReader(streamReader, csvConfig))
            {
                var records = csvReader.GetRecords<Read>().ToList();
                List<DataPoint> Parametry_A, Parametry_B, Parametry_C, Parametry_D, Parametry_E;
                NewListDeclarate(out Parametry_A, out Parametry_B, out Parametry_C, out Parametry_D, out Parametry_E);
                foreach (var record in records)
                {
                    if (DateVerification(record))
                    {
                        DateTime label_date;
                        DataPoint dataPointA, dataPointB, dataPointC, dataPointD, dataPointE;
                        NewPointsGenerate(record, out label_date, out dataPointA, out dataPointB, out dataPointC, out dataPointD, out dataPointE, FirstParameter_name, SecondParameter_name, ThirdParameter_name, FourthParameter_name, FivethParameter_name);
                        if (UserDateCheck(dateStartobj, dateEndobj, label_date))
                        {
                            AddPointsToList(Parametry_A, Parametry_B, Parametry_C, Parametry_D, Parametry_E, dataPointA, dataPointB, dataPointC, dataPointD, dataPointE);
                        }
                    }
                }
                ReturnListsToViewBag(Parametry_A, Parametry_B, Parametry_C, Parametry_D, Parametry_E);
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文