用户上传的图片可以存放在哪个文件夹中
我在 ASP.NET/c#/MS SQL 上有一个分类广告系统,我试图找出在哪里存储人们在放置广告时上传的图像。广告本身存储在 SQL Server 数据库中。
这些图像现在存储在我的 web 应用程序的子文件夹中。看起来工作正常,但我最近才发现一个大问题。每次用户删除广告时,附加的图像也会被删除,包括它们所在的文件夹。这会导致 ASP.NET 应用程序重新启动。我搜索了互联网,发现重新启动网络应用程序实际上是删除子文件夹时的预期行为。
显然,我需要解决这个问题。但如何做到这一点呢?我可以在哪里存储图像,以便:
- 我可以删除这些图像,包括它们存储的文件夹?
- 我可以使用 URL 访问它们(图像需要显示在 网页)
- 没有得到网络应用程序 重新启动? 如有任何反馈,我们将不胜感激! 保罗
I've a classified ads system on ASP.NET/c#/MS SQL, and I'm trying to figure out where to store the images that people upload when placing an ad. The ad itself is being stored in a SQL server database.
The images are now being stored in a subfolder of my webapp. It seems to work fine, however I only recently discovered a big problem. Everytime a user deletes an ad, the attached images are to be deleted as well including the folder they reside in. This leads to a restart of the asp.net application. I searched internet and found that restarting the web-app is actually intended behaviour when a subfolder is being deleted.
Obviously, I need to fix this. But how to do that? Where can I store images in such a way that:
- I can remove these images including the folders they are stored in?
- I can acces them using a URL (the images need to be shown in the
webpages) - Without getting the web-app being
restarted?
Any feedback is appreciated!
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅此问题删除目录会导致应用程序重新启动
另一种选择是将图像存储在数据库中。
See this question Deleting a directory results in application restart
An other alternative would be to store the images in the DB instead.
另一种选择是将图像放在与网站完全无关的目录中,然后通过脚本页面或处理程序提供图像。它会使您的所有图像网址看起来像
mydomaincom/serveimage.aspx?imageid=323422
,但除非您指望某个地方的名称,否则这实际上并不重要。显然,首先也需要对提供图像的页面进行修改,但如果删除了这个不相关目录的子目录,IIS 实际上根本不应该关心。Another option would be to put the images in a directory completely unrelated to the web site then serve the images through a scripted page or handler. It would make all of your image urls look like
mydomaincom/serveimage.aspx?imageid=323422
, but unless you're counting on the name somewhere that really shouldn't matter much. Obviously it would require a modification to the page that serves the images in the first place as well, but if sub directories of this unrelated directory are deleted IIS really shouldn't care at all.也许你可以将图像存储在 SQL 中(在本例中检查文件流功能)
如果没有,我想您在业务门面类、服务类或任何您想要的地方有一个方法“DeleteAd”。
这个方法必须做两件事:
-删除sql数据
- 也删除文件图像
,您可以将图像存储更改为网络应用程序之外的另一个文件夹。您可能最终会编写一个自定义处理程序 (myhandler.ashx?fileid=XX) 来提供文件服务,或者如果您使用 MVC,则编写一个自定义路由和控件。
maybe you can store the images in SQL (check at the filestream feature in this case)
if not, I suppose you have somewhere in a business facade class, a service class or wherever you want, a methode "DeleteAd".
This method will have to do two things :
-delete the sql data
-delete the file image
also, you may change the image store to another folder, outside the web app. You will probably end with writing a custom handler (myhandler.ashx?fileid=XX) to serve the files, or a custom route and control if you use MVC.