We're currently building a WebService that will run under IIS.
Our current dilemma is where to store uploaded files?
Up until now we saved the files directly under the physical path of the virtual directory but than we found out that the application pool restarts when files are deleted under one of its physical paths.
We think of storing the files under the ProgramData folder but we're afraid of breaking changes with new windows updates.
Where would be a correct and safe place to store the files?
Is the ProgramData good enough?
I really dont understand why you are putting this files directly in the root? just create a folder called Files instead and put your files there. then your application pool doesnt restart:)
or else read up how to create your own mini-CDN:)
http://www.saotn.org/create-cdn-using-iis-outbound-rules/
and DONT use the programdata.it is designed for userdata and not to drive your webpage
Really? Deleting a file restarts the application pool? What are you doing with these file? Are they resources of your application? Basically saving the files in any partition different from the system's partition should be fine. Even saving them in a folder inside your application's physical path...deleting the files shouldn't cause the application pool to recycle. But, a safer solution would be to save them in a separate server if you happen to need several instances of your web service in a load balanced environment
Related
I am developing a simple C# console application for use in an industrial setting. This application takes a product id number, and then configures an XML file and saves it to a folder location. The operators then load this XML file into a laser printer that engraves data onto a product. This app will be used on multiple computers, and not installed by me.
Right now I have hardcoded in filepaths for the XML file templates (C:\XmlGen\SourceTempplates), and the location that the configured files are saved (C:\XMLGen\OutputXml). Now, if the app gets installed on a computer and moved somewhere, the application will not be able to find the templates or save the configured files. Is there a way that I can write these filepaths so that the application can still find the files? (Say for example, it gets installed to a D:\ drive instead of C).
Thanks! Let me know if I need to provide more info.
Its generally a good practice to use defined environment folder to store application generated files instead of using hardcoded drive letter.
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
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? 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. What kind of data you store there is up to you. Note that there are 3 on a Windows:
ApplicationData
CommonApplicationData
LocalApplicationData
Generally data in there it should be data specific to this user - except for CommonApplicationData, of course. Being shared across users, is what the "Common" Prefixed Folders are there for.
However the rest of the question makes no sense. 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://learn.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. Of course only now I noticed MVC properly.
WebServers are uniquely vulnerable to hacking. Online 24/7, a few well known frameworks and widespread reachability as a core goal. 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. Maybe write access in a subfolder of content for Temp files - but there are better solutions, that involve Databases and HTTP Handlers.
Solution:
If you want your images to be avalible, put them into a subfolder of the Content directory for this instance. 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. But I doubt you are on that scale yet.
Quote from the Azure Web Jobs Documentation:
Persisted files
This is what you can view as your web site's files. They follow a
structure described here. They are rooted in d:\home, which can also
be found using the %HOME% environment variable.
These files are persistent, meaning that you can rely on them staying
there until you do something to change them. Also, they are shared
between all instances of your site (when you scale it up to multiple
instances). Internally, the way this works is that they are stored in
Azure Storage instead of living on the local file system.
Does that imply that by dropping app_offline.htm into the site root folder should pretty much bring down all instances simultaneously?
Yes.
It doesn't bring them down exactly just redirects all traffic to that htm file.
And it's easy to try for example using Visual Studio Online editor:
http://dotnet.dzone.com/articles/first-look-visual-studio
Or the DebugConsole:
http://azure.microsoft.com/blog/2014/03/04/windows-azure-websites-online-tools-you-should-know-about/
Just add the file to wwwroot and browse to your site.
I am currently developing a ClickOnce application that converts CSV files for a database update. The program requires the user to have the ability to change the configuration files for a database change, and change an XML file which populates a drop-down list in the app.
Now I understand that the files are kept in the user/appdata folder to ensure there have the correct privileges, but do I have any influence as to what those folders are called, or where they are saved?
By default, the files are saved in AppData\Local\Apps\2.0\LD7ZEJK0.7AE\NJ42PEPW.1QX\csvt...exe_169e1a4011fbe7ec_0001.0000_none_04507fe9e077ae84
Can I change that to say Documents\CSV_Files or something similar? And if I do, how would I reference the XML file in the configuration file so the program knows where it is?
Normally, you shouldn't have to care about the location yourself. Just mark your XML file as data in the ClickOnce manifest and access it using the well-known:
ApplicationDeployment.CurrentDeployment.DataDirectory
Here's an MSDN article describing it: Accessing Local and Remote Data in ClickOnce Applications
I would never store any data that is important to be retained in the case of an update in the actual ClickOnce deployment directories -- it is too dangerous. You should copy those files out to ApplicationData and access them there. This article shows you how to do that.
I have a little payments webApp, our customers can install it on their IIS and work with it. They can upload their own logotype.
We are using WyBuild to update this apps, but it replaces all files on the web folder with the new version, so the logotypes are deleted, that's why we placed the customer's files in program files, so the updater can't delete them.
the problem is that I can't load the images from the following path
C:\Program Files\MyApp\ImageFoder\logo.jpg
I don't know how to do it and I'm almost sure that is not possible to load
My web application is on
C:\inetpub\wwwroot\MyApp\
I can't have the images on the webFolder because wyBuild deletes them when I'm trying to update them, I already tried the paths like this: (the don't work)
///file:c:/program files/ .... etc
so, the question is
How can I load an image to an asp:image control using it's windows path ?
You need to configure an IIS Virtual Folder to point to the alternate location where the images are stored.
I wouldn't put them in Program Files, though, a sibling folder in wwwroot would be better.
Remember NTFS permissions are easy to mess up and it's easier to manage them in a single place.
Update - for locally installed, localhost-only sites Alternatively (and this is only a good idea if you have minimal amounts of traffic. NOT for public websites), you can serve files from an arbitrary location using a VirtualPathProvider. It sounds like this 'web app' is installed like a desktop app for some reason? If you want to store user data externally, the user's App Data folder would be appropriate, but ONLY if the web app refuses external connections, and can only be accessed from the machine.
Since you're dealing with images, I'd grab the imageresizing.net library and use the VirtualFolder plugin to serve the files dynamically. It's 200KB more in your project, but you get free dynamic image resizing and/or processing if you need it, and you save a few days making a VirtualPathProvider subclass work (they're a nightmare).
Wouldn't it be better to use isolated storage?
Added: I mean on the users machine, and upload them again if they are not found. This takes away your overhead completely.