Solved

Locating App_Data in web apps

Posted on 2010-09-03
7
917 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:tedbilly
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 51

Accepted Solution

by:
tedbilly earned 500 total points
Comment Utility
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:tedbilly
Comment Utility
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
Comment Utility
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:tedbilly
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now