良好做法在ASP.NET的Web API对文件进行操作? [英] Good practice for working with files in ASP.NET web api?

查看:91
本文介绍了良好做法在ASP.NET的Web API对文件进行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新处理文件工作,所以我也做了一些阅读,altough我觉得我还是不能确定如何使用asp.net网站的API来对付他们。
我要的是要能够通过我的网络API达到图像。什么到目前为止,我读过的是,很多人preFER保存文件,然后调用而不是图像保存到数据库ü只能保存URI有其URI。所以,我再上创建的网络API,它正是这样做的(ATLEAST使用本地主机的工作)一imageController。我现在得到了一些人争辩说,我应该使用Blob存储(因为我使用的Azure)。

I'm new working with files so i have done some reading, altough i feel that i'm still not certain how to deal with them using asp.net web api. What i want is to be able to reach images thru my web api. What i've read so far is that many people prefer saving the file and then call for its URI, instead of saving the image to the database u only save the URI there. So I then created a imageController on the web api that does exactly this(Atleast working using localhost). I now get some people arguing that i should use blob storage(since i use Azure).

我的问题是:它是错的或不好的做法,在我的项目文件夹中保存我的图片文件?否则这将是更好的方式来保存图像?

My question is: Is it wrong or bad practice to have a folder in my project where i save my image files? Else what would be the better way to save images?

推荐答案

您的问题实际上是两个问题:

Your question is really two questions:

这取决于两个主要因素:安全性和性能

It depends on 2 main factors: security and performance.

如果您的图片敏感,访问它们的风险外您的应用程序(例如,通过盗链)是不可接受的,你必须去的数据库,并通过ASP.NET请求提供图片 - 你可以验证,无论如何你想。但是,这样做花费更多的资源密集型比第二个选项(见下文)。

If your images are sensitive and the risk of accessing them "outside" your app (for example by hotlinking) is unacceptable, you must go for database, and serving images via ASP.NET request - which you can authenticate any way you want. However, this is MUCH more resources-intensive than second option (see below).

如果安全性不用担心,你肯定想要去的文件系统存储。在传统的主机,你会无处不在保存在磁盘上,而IIS(Web服务器)会为他们服务用户(通过直接URL,绕过你的ASP.NET应用程序)。仅此一点已经结束的原因很多(请求线程池,内存pressure,平均持续时间的要求,缓存在IIS ...)DB + ASP.NET解决巨大的性能提升。

If security is no concern, you definitely want to go for filesystem storage. On traditional hosting, you would save them "anywhere" on disk, and the IIS (the webserver) would serve them to user (by direct URL, bypassing your ASP.NET application). This alone is HUGE performance improvement over DB+ASP.NET solution for many reasons (request thread pool, memory pressure, avg. request duration, caching on IIS...).

不过,在Azure中就可以了,并有进一步走一步 - 使用专用Blob存储,独立于你的Web角色,所以连你的webrole IIS会为他们提供服务,但在Blob存储专用服务器(这样做并不需要在所有关心你 - 它只是工作)。您的Web角色不应该永久存储任何东西 - 它可能会失败,被销毁并在通过Azure结构随时更换新的。所有永久的东西必须去的Azure Blob存储。

However, in Azure you can, and HAVE TO go one step further - use dedicated blob storage, independent from your web role, so not even your IIS on webrole will be serving them, but dedicated server on blob storage (this does not need to concern you at all - it just works). Your web role should not store anything permanently - it can fail, be destroyed and replaced with new one at any time by Azure fabric. All permanent stuff must go to Azure blob storage.

这篇关于良好做法在ASP.NET的Web API对文件进行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆