Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 951
  • Last Modified:

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,
0
ScottMacMaster
Asked:
ScottMacMaster
  • 4
  • 2
1 Solution
 
Ted BouskillSenior Software DeveloperCommented:
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
 
carlnorrbomCommented:
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
 
ScottMacMasterAuthor Commented:
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
Industry Leaders: 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!

 
Ted BouskillSenior Software DeveloperCommented:
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
 
Ted BouskillSenior Software DeveloperCommented:
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
 
ScottMacMasterAuthor Commented:
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
 
Ted BouskillSenior Software DeveloperCommented:
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

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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now