简体   繁体   English

我可以在我的 C# ASP.NET MVC 应用程序中将 App_Data 文件夹用作普通文件夹吗?

[英]Can I use App_Data folder as a normal folder in my C# ASP.NET MVC application?

I understand this folder App_Data is normally for database files etc but I want this now for images, the idea being users upload images into this folder and they can be accessed from the website, I basically want App_Data to be used/thought of as a normal folder now, anyone know how to do this?我知道这个文件夹App_Data通常用于数据库文件等,但我现在想要这个用于图像,想法是用户将图像上传到这个文件夹并且可以从网站访问它们,我基本上希望App_Data被使用/认为是正常的现在文件夹,有人知道怎么做吗? Is it just permission settings or can this folder not be used like a normal folder.只是权限设置还是这个文件夹不能像普通文件夹一样使用。 Thanks in advance:)提前致谢:)

ApplicationData is a folder for Application Data. ApplicationData 是应用程序数据的文件夹。 What kind of data you store there is up to you.您在那里存储什么样的数据取决于您。 Note that there are 3 on a Windows:请注意,Windows 上有 3 个:

  • ApplicationData应用数据
  • CommonApplicationData通用应用程序数据
  • LocalApplicationData本地应用程序数据

Generally data in there it should be data specific to this user - except for CommonApplicationData, of course.通常,那里的数据应该是特定于该用户的数据 - 当然,CommonApplicationData 除外。 Being shared across users, is what the "Common" Prefixed Folders are there for.在用户之间共享是“通用”前缀文件夹的用途。

However the rest of the question makes no sense.然而,问题的 rest 没有任何意义。 You want the user to manually put stuff there, so a WebSite can upload it?您希望用户手动将内容放在那里,以便网站可以上传吗? You also seem to think it is somehow not a "normal" folder?您似乎还认为它在某种程度上不是“正常”文件夹?

WebSites do not have random access to the file System.网站不能随机访问文件系统。 So it would really just be annoying for the user to navigate there.因此,用户在那里导航真的很烦人。 And if there is another programm in the loop, you have not told us of it.如果循环中有另一个程序,你还没有告诉我们。

And the folder is quite normal.而且文件夹很正常。 The OS stores a path to it wich can be changed (and the file moved Automagically), but beyond that it is as normal as can be.操作系统存储了一个可以更改的路径(并且文件自动移动),但除此之外它是正常的。 The unknown position is why you should always retreive the real values from the OS with https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder未知的 position 是为什么您应该始终使用https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder从操作系统中检索实际值的原因

Edit:编辑:

Based on your comment, I understand now.根据你的评论,我现在明白了。 You are writing a Website.你正在一个网站。 And you wonder why the server has no access to the AppData Folder.您想知道为什么服务器无法访问 AppData 文件夹。 Of course only now I noticed MVC properly.当然,直到现在我才正确地注意到 MVC。

WebServers are uniquely vulnerable to hacking. Web 服务器特别容易受到黑客攻击。 Online 24/7, a few well known frameworks and widespread reachability as a core goal. 24/7 在线,一些众所周知的框架和广泛的可访问性作为核心目标。 As a result they generally run under the most restrictive userrights possible .因此,它们通常在可能的最严格的用户权限下运行。

Read access to the servers programm and the Instances content directory - any more can not be expected and should never be granted.对服务器程序和 Instances 内容目录的读取访问权限 - 不再有任何期望,也不应该被授予。 Maybe write access in a subfolder of content for Temp files - but there are better solutions, that involve Databases and HTTP Handlers.也许在临时文件的内容子文件夹中写入访问权限 - 但有更好的解决方案,涉及数据库和 HTTP 处理程序。

Solution:解决方案:

If you want your images to be avalible, put them into a subfolder of the Content directory for this instance.如果您希望您的图像可用,请将它们放入此实例的Content目录的子文件夹中。 However you really should be considered Database Storage with HTTP Handlers: https://www.red-gate.com/simple-talk/sql/learn-sql-server/an-introduction-to-sql-server-filestream/ Some even go as far as having a seperate, dedicated Webserver just for Images.但是,您确实应该考虑使用 HTTP 处理程序的数据库存储: https://www.red-gate.com/simple-talk/sql/learn-sql-server/an-introduction-to-sql-server-filestream/有些甚至go 有一个单独的专用网络服务器,仅用于图像。 But I doubt you are on that scale yet.但我怀疑你还没有达到那个规模。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将数据写入ASP.NET MVC中的App_Data文件夹? - How can I write data to the App_Data folder in ASP.NET MVC? 如何让 Visual Studio 使用我的数据库,而不是位于 ASP.NET MVC 项目的 App_Data 文件夹中的 .mdf 文件? - How can I make Visual Studio use my database instead of the .mdf file located in App_Data folder in ASP.NET MVC project? 如何在ASP.NET Web应用程序的App_Data文件夹中引用Sqlite db文件? - How do I reference the Sqlite db file in the App_Data folder for my ASP.NET Web Application? ASP.Net vNext App_Data文件夹 - ASP.Net vNext App_Data folder 如何允许仅在App_Data asp.net mvc中下载访问特定文件夹 - how to allow download access to specific folder only in App_Data asp.net mvc 如何删除“ / App_Data / uploads”文件夹中的上载文件ASP.NET MVC - How to delete the uploaded files in the “/App_Data/uploads” folder ASP.NET MVC ASP.NET MVC中App_Data文件夹下缺少.mdf文件 - .mdf file missing under the App_Data folder in ASP.NET MVC 想要在实时服务器中上传文件,而不是ASP.Net MVC中的App_Data文件夹 - Want to upload file in the live server other than App_Data folder in ASP.Net MVC 在Visual Studio 2012的ASP.NET中未获取App_data文件夹 - Not getting App_data folder in ASP.NET in Visual Studio 2012 如何为存储在asp.net的app_data文件夹中的文件提供URL - How to give URL for a file stored in app_data folder in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM