将我的 ASP.NET MVC Web 应用程序发布到 IIS 后,无法上传内容文件夹内的文件

2024-01-26

我有以下操作方法,它将上传的文件添加到文件夹中:-

if (ModelState.IsValid)
                {
                    string ADusername = User.Identity.Name.Substring(User.Identity.Name.IndexOf("\\") + 1);
                    repository.InsertOrUpdateDataCenter(dc, ADusername);
                    repository.Save();
                    if (DataCenterfile != null)
                    {
                        var fileName = Path.GetFileName(DataCenterfile.FileName);

                        var path = Path.Combine(Server.MapPath(Url.Content("~/Content/uploads")), dc.ID + ".png");
                        DataCenterfile.SaveAs(path);
                    }
                    return RedirectToAction("Details", new { id = dc.ID });
                }

但我收到以下异常:-

Server Error in '/TMS' Application.

Could not find a part of the path 'C:\inetpub\wwwroot\TMS\Content\uploads\97.png'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\inetpub\wwwroot\TMS\Content\uploads\97.png'.

Source Error: 

请记住,上述内容运行良好,但在我将 Web 应用程序发布到 IIS 后,我开始收到此错误。那么有人可以建议我如何解决这个问题吗? 谢谢


I believe你要做的就是设置“构建操作”Content文件夹作为“内容”。

您可以通过在解决方案资源管理器中选择文件夹,然后转到“属性”来执行此操作。在那里您将看到“构建操作”选项。将其设置为“内容”,或者“无”。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将我的 ASP.NET MVC Web 应用程序发布到 IIS 后,无法上传内容文件夹内的文件 的相关文章

随机推荐