Solved

Locating App_Data in web apps

Posted on 2010-09-03
7
927 Views
Last Modified: 2012-08-13
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,
0
Comment
Question by:ScottMacMaster
  • 4
  • 2
7 Comments
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 33601888
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.
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 33602356
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.
0
 

Author Comment

by:ScottMacMaster
ID: 33603616
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,
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 500 total points
ID: 33604169
For an understanding of the paths used in .NET this link has your answers: http://msdn.microsoft.com/en-us/library/ex526337.aspx

If the license file is only for server side code then use a physical path instead.  This URL has your choices for accessing all the web paths including the physical ones: http://msdn.microsoft.com/en-us/library/ms178116.aspx

So does this one: http://www.west-wind.com/weblog/posts/132081.aspx  In fact, this guy writes a lot of good blogs on .NET

If the component needs to retrieve the license file from the client then I'd simply move it to the root of the website and refer to it there.  However I doubt that the license is sent to the client.  That would be a less secure design and could mean the license could be stolen.

So, a physical path is likely the best location and I'd put it in the bin folder.
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 33604173
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.
0
 

Author Comment

by:ScottMacMaster
ID: 33621526
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
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 33621591
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question