Link to home
Start Free TrialLog in
Avatar of ScottMacMaster
ScottMacMaster

asked on

Locating App_Data in web apps

I recently switched to using the new Visual Studio 2010 for developing apps.  Things mostly went smoothly.  However, there's one issue I haven't be able to resolve.

In the past, Visual Studio put the App_Data in the root of the web app directory structure (matching the project layout).  However, Visual Studio 2010 moves it under the bin directory when I publish the web app.  So my code that references files in App_Data that works fine in testing is suddenly broken when I publish the web app.  To deal with this I've just been copying App_Data to the root and avoid using the 'delete files before publish' option when I don't need to (so I don't have to copy App_Data everytime a publish a web app).

So my questions, is there a way to define a path that works in both development and live environments?  Or is there a way to tell Visual Studio to publish App_Data to the root?  Or should I be doing something different?


Thanks,
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

There are some security benefits to having the App_Data folder in the bin folder.  ASP.NET won't answer GET requests to anything in the \bin\ sub folder so it effectively hides it from hackers.

Can you include the code for accessing the paths?  I can show you how to get access to common folders in .NET based on your snippets.

Personally I don't use the App_Data folder because I convert all my VS Web Sites to Web Applications.
Hi!

Also you have the option of using different web.config files, one for debug, one for staging, one for release etc. This is natively supported in VS2010. Then you can specify the connectionstrings differently depending on the hosting environment.

/Carl.
Avatar of ScottMacMaster
ScottMacMaster

ASKER

Well, here's an code example.

        license.SetLicense(Server.MapPath("~/APP_DATA/Aspose.Cells.lic"))

The license is for the third party product, Aspose.Cells.  It's really the only thing I even have in the App_Data folder.  The tilde is the only macro I know of for accessing locations in a web app.  Are there more?  I'd definitely like to review a list of them.

I also don't like to use web sites.  I prefer web applications.  However, it obviously still lets me use App_Data in web apps.  Maybe I don't understand the purpose of the App_Data folder.  WHat's supposed to go in it?  Maybe I shouldn't use it and should create a separate folder for the license folder like how I create a separate folders for images and javascripts files.

The option to use different config files for debug, staging, a release sounds interesting.  Unfortunately, I work in a one man development team and I don't have time to test stuff in different environments.  I need stuff to be as similiar as possible between the development and producation environment.

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way as a one man shop I think it's VERY important that you invest time in learning new techniques because in the long term it might save you time.

Think of it this way, learning how to use different config files might take an hour but over a year it might save you days in physical work.

The most successful developers I know spend a little time every day learning to be more efficient.
I can see the use of having multiple config files.  I was going to try that out but it won't let me.  Maybe because I used the convert wizard to convert the project from 2008 to 2010.  It seems to work for new projects.

Anyway, I wouldn't have much use for them here.  I don't create production programs here.  I write inhouse programs for reporting and other purposes.  I found it to be better to put all the connection strings in machine.config.  That way I can quickly change the database path for the 30 plus programs I have out there.  Plus I can still override the settings in the programs config file if I need to test something.

Anyway, to get back to my questions.  I wasn't looking for an explanation of paths.  I was looking for a macro of something like that that would translate to the location of App_Data.  Something like the system paths in windows (for example, %windir%).  That way if they changed the location of App_Data or other special folders it wouldn't break my program by me using a hard coded path.

Thanks, for the suggestion about that I don't need it in the web app folder or sub subfolder.  It never occured to me that I could do that.  I now have it on the server that we have the license managers on for different products we have.  So I guess this makes for question go away.  Although I would still like to know if there's things like %windir% for special web app folders.


Thanks
If you read the examples in the articles I gave you they do give you the equivalent to %windir% which is the root of your web application.  From there the relative paths are trivial to find.

I too build internal web applications for reporting et cetera (for a company of 10,000+) however I still treat development like a commercial operation because I call them 'Line of Business' applications.  My internal customers get very angry if there is down time during the day so our small (2 developer team) is very careful and deliberate about changing production.

In fact, we have a %99.999 percent up time rate for our systems which are used globally and are very proud of that.