views:

111

answers:

5

I have an ASP.NET page that will run on a shared hosting service (e.i. I'm leasing space on a single server that also serves content for other people) and I need a way to find a directory that I can save files in and that will not get hosted as web content. The file will be long lived and should be the same across sessions, visits, etc. I think App_data might work.

Is there a method or property that will give me an absolute path to such a directory?


Kinda like this question that doesn't have a useful answerer.

+1  A: 

Get a fileserver going.

Or a shared directory that all the web servers can access.

Chris Brandsma
I don't own any servers where that can be done :(
BCS
By the question you asked, you have multiple web servers, delegate one of them as a file server and web server.(see if you can add a separate disk as well, put the files on the new disk). Share the folder, and have all the web servers access the shared folder.
Chris Brandsma
If you are dealing with a single web server...App_Data
Chris Brandsma
Why are you assuming I have more than one server? The 'etc.' in 'sessions, visits, etc.'? It does NOT include servers.
BCS
Because, in general, people only worry about sharing files when they are dealing with web farms. Since you are not, you have an easy answer: stick everything in App_Data and not worry about it.
Chris Brandsma
+3  A: 

in /App_Data/ ?

Morten
How do I find the path to that? I'm not willing to go on blind faith that `./App_Date/` will get me to the right spot.
BCS
@BCS: `Server.MapPath("~/App_Data")`
Fredrik Mörk
Where is `Server`? the only links Google is finding seem to be for use in .aspx files and I need this in a .cs file.
BCS
It seems I can get to one under `HttpContext.Current.Server`... now to see if it works.
BCS
@BCS, yes either `HttpContext.Current.Server` or the `Server` property of the current `Page` (if you are within a page request).
Fredrik Mörk
A: 

Due to permissions that must be established on the directory housing these files it is usually for the best that it not be in your application's path. Other than that it really just comes down to what you have available, and how you want to manage it.

Matthew Vines
+4  A: 

App_Data is safe because by default you can't download file from there by typing in a URL to your browser.

IsolatedStorage is good if you need to isolate users from each other. IsolatedStorage requires less collaboration with your IIS admin when it comes to granting NTFS rights to folders outside of your virtual directory. Blobs in the database are possibilities, too but the extra effort involved with blobs in databases makes it a last resort choice.

MatthewMartin
A: 

If data is static - you can store it in resources too.
At least - i haven't heard any arguments why that is bad.

Arnis L.
It's not static :(
BCS
Then use App_data as Morten already mentioned.
Arnis L.