[英]Write and Delete Files in Web Root Folder When Using FTP in ASP.NET Core
I'm making a web shop using ASP.NET Core Razor Pages and as a part of this I want to perform CRUD operations for product images.我正在使用 ASP.NET 核心 Razor 页面创建一个 web 商店,作为其中的一部分,我想对产品图像执行 CRUD 操作。
My Admin page for writing image files looks like this:我的用于写入图像文件的管理页面如下所示:
public IFormFile Thumbnail { get; set; }
public AddModel(IWebHostEnvironment webHostEnvironment)
{
_webHostEnvironment = webHostEnvironment;
}
public void WriteImage(string reference)
{
string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images", "products", Product.Name.ToLower());
if (!Directory.Exists(uploadsFolder))
{
Directory.CreateDirectory(uploadsFolder);
}
string thumbnailPath = $"{Product.Name.ToLower()}-{reference}-thumbnail.png";
string fileLocation = Path.Combine(uploadsFolder, thumbnailPath);
using (var fileStream = new FileStream(fileLocation, FileMode.Create))
{
Thumbnail.CopyTo(fileStream);
}
}
Everything works in development.一切都在发展中。 Though I suspect things will be different once the site goes live.
尽管我怀疑网站上线后情况会有所不同。 I'm planning to publish the website with FTP using FileZilla, and don't I need to log in to the FTP server in order to write and delete files located in the Web Root Path?
我打算使用 FileZilla 发布 FTP 的网站,我是否需要登录到 FTP 服务器才能写入和删除位于 Web 根路径中的文件?
You cannot just upload your app to any FTP server, you also need to be able to run your app somehow.您不能只将您的应用程序上传到任何 FTP 服务器,您还需要能够以某种方式运行您的应用程序。 See Host and deploy ASP.NET Core for further information.
有关详细信息,请参阅 托管和部署 ASP.NET 核心。 Your app will run as certain user, and as such does not need to logon again to access the server's file system, but it depends on the server to which directories your app will have access to.
您的应用程序将以特定用户身份运行,因此无需再次登录即可访问服务器的文件系统,但这取决于您的应用程序可以访问哪些目录的服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.