开发者

In which folder can I store user uploaded images

开发者 https://www.devze.com 2023-02-09 22:23 出处:网络
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 databas

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


See this question Deleting a directory results in application restart

An other alternative would be to store the images in the DB instead.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号