We help IT Professionals succeed at work.

The directory '/SiteName/App_Code/' is not allowed because the application is precompiled.

forsters asked
Hi Experts,

Just been following a tutorial to add a stored proceedure to my site.

The steps involved adding an App_Code folder to store my new class in, but because the site is precompiled I seem to be unable to do this, is there a way round?  

I'm using VS2010 .net 4.0 if that has any bearing on things...
Watch Question

lojk.Net and Infrastructure Consultant
VS2010 does not support 'copying' of sites (like the older versions) did, rather it publishes as Precompiled by default (and therefore App_Code is irrelevant as it is already compiled).

Just skip the whole App_Code process and add it as a class/file/whatever in the relevant folder location within your site - it should work but see the next bit to understand why not.

The clue is in the name - the 'WebSite' proejct should only contain stuff that relates to the site (UI) layer and you should really be splitting your site into a multi-tier configuration with the Execution Logic stored in a seperate class library and added as a reference to your site.


Hi Lojk,

Ok thanks for this, i'd just been reading a forum where someone had same problem, he was advised to copy site to server (host) rather than publish, the copy Web Site option does still exist is VS2010 I just didn't know about it until now.

So forgive my ignorance but your next comment is interesting because i'm relatively new to VS having moved over from DW.

In an ideal world I want to have my site in VS and Ctrl f5 to check and view my changes then when i'm ready publish/copy the bits I want to the server but be able to keep adding to and changing the site in this way. Is that approach good practice...it's what i'm used to...not sure how else to set things up?

Can you explain further your comment about having a multi-tier configuration, i'd like to understand this more because I keep coming across it but no idea how to begin setting a site up in this way...I'm still getting used to having code-behind and master pages, but i'd really love to get a handle on the bigger picture.

Many thanks an insight would be really appreciated
lojk.Net and Infrastructure Consultant
You are talking about a website (in a fairly typcial 'web developer' way)- but think of it more like a Web Application that you publish as a whole - like a Windows Appplication, you dont publish only parts of that - it is all tested together and compiled and published together. Yes if you can find a way to copy the site, that will work (with my original comment) but I NEVER do that.

I see lots of web developers wanting to do this partial publish - it is a nightmare to keep web.config files in sync and you end up missing bits off during the publish and having to debug why page_x doesnt work and it turns out because you have forgotten to include class_y when you (as an unreliable human) missed it.

Yes - you can still do things in code-behind but only the things that relate to the UI of the page in question (e.g. you might click a button that hides a panel, that stays in code behind but the button handler that starts the import routine doesnt contain that actually does the import) - bundling a whole bunch of application logic in there just ties you into a situation where you can't test your site (operations) because you have to /do a load of stuff/ to make it appear in a browser. If you split the logic into a UnitOfWork (a class that you can instantiate) it can be included in the site AND also referenced by a rough windows application with a group of 'Test This Thing' buttons (or a proper unit test if you are that way inclined).

Multi-Tier is just a fancy name for creating a pool of code that does the work that is not tied to the upper/presentation/ui layers - Microsoft dont have one big fat 500MB executable called Windows.EXE (well they did kind of used to ) - it is all split into individual component dlls targetting each individual task.

As a (severely truncated) example - in all my sites i have a 'toolbox' project that contains Helper Methods to convert StringsToNumbers, StringsToFiles, BytesToString, etc. Then i have a site logic project that references the toolbox that contains the business Logic - classes that ConnectToDatabases, AddCustomers, ExportReportsToDocuments, etc.. then I have a WebApplication/UI project that references those lower layers containing Views,Controls,Presentation etc.

(One other major benefit here is that my toolbox layer can continue growing and having new stuff added and be reused many, many times -generally increasing productivity as long as sensible control is applied to it... )

In that WebApplication there is a page that Contains a Button called DoManualFileImport that looks a bit like this in its code-behind... (some names changed to protect the innocent ;-) )

 protected void ManualUploadWizard_Step2_Next_Click(object sender, EventArgs e)
            MyBusinessLogicProject.StudentImportInstance tNewInstance = new   MyBusinessLogicProject.StudentImportInstance();

            if (tNewInstance.CanTheNextSyncJobBeStarted(2))
                System.Threading.Thread tNewThread = new System.Threading.Thread(new System.Threading.ThreadStart(DoIt));
                this.lblResults.Text = "Launched on new thread - check Log for more info.";
                this.lblResults.Text = "System is busy - Please try again later.";

 private void DoIt()
            string LogfileLocation = (this.Page.Master as MasterPage_Extended).GetAbsoluteFromRelativePath
           ("~/ManualFileUpload/Logs/" + DateTime.Now .ToString ("yyyyMMddHHmmss")  + ".log"); // dont worry too much about the line, just understand that it sets the error log location
          MyBusinessLogicProject.StudentImportInstance tNewInstance = new   MyBusinessLogicProject.StudentImportInstance();

tNewInstance.StartImport (LogFileLocation);

As sites get bigger and smarter, splitting them into smaller peices improves readability and reusability and consequently makes human intervention publishing more difficult and the sooner you do it (and you will HAVE to do it eventually) in the development lifecycle the easier it is.

Does that clarify it for you?


Umm, kinda.

I get the logic, just don't know how to set up a web App with this structure...for example where you say that you have a 'toolbox' project in all your sites - what I don't understand is how you do that..what is it, one page, several pages, is it a file, whats the filetype or does that vary? where is is, is it physically in your site or is it a seperate project that you call from your site?

This is the first time I've had to use a class so unchartered territory altogether, until now all my connection strings have lived in my web.config and I used SqlDataSource on my aspx page with a few bits and bobs in code behind for a button-click events etc, nothing much more complex than that so i'm not really clear on how all these 'layers' fit together or where they live in relation to the UI part of the site and each other...but I do see the point of them.

We've strayed off-piste somewhat but if you have time to point me in the right direction i'm interested and would be glad of the insight...points of-course are yours.
lojk.Net and Infrastructure Consultant
You asked for an insight, thats what you got! I actually dont think we have strayed at all ;-)

Check out the screen shot (again protecting the innocent) - it shows the Site and the Site Logic projects (its just a simple 'class library project') and the references to the toolbox projects (although they are are way off down the bottom of the solution).

I know - It all feels kinda funky now, I remember that feeling but hopefully you'll remember this thread later and eventually heed some of it's warnings and advice (and it serves my purposes as i can add it as an EE Knowledgebase article for my reference too).




Thanks for screen shot, i'm really none the wiser as i'm sure you know so thanks i've clearly got a long-way to go before that makes sense but getting back to the original problem of My precompiled site not liking my new addition of an App_code folder, containing one class - in  a namespace, how do I resolve?

If I remove the App_code folder as suggested and put my class elsewhere, the reference to my namespace / class isn't found...
lojk.Net and Infrastructure Consultant
in the place where you are trying to consume the code...

either use


or do (at the top of the file )   << this is the better option IMHO

Using The.Full.Namespace

and where you need to call it...


Has that got it?


Well I think thats what I have...

So I have the 3 pages:-
class file (.cs) now living in same folder as my .aspx page and it's .aspx.cs code behind page

My class file has:

namespace MyNameSpace
public class StoredProcedures
and so on...

My code behind page is calling my class file as follows:

using MyNameSpace;

public partial class MyFolder_MySubFolder_MyPage : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)
    Repeater1.DataSource = StoredProcedures.MyStoredProcedureName();

(the Repeater is obviously sitting in my .aspx page ready for action) but on the code behind the namespace is underlined 'could not be found' and so consequently the class 'StoredProcedures' is too

am I being daft, i've assumed that as the namespace is of my own making there are no prefixes to it's name because it's not a System.Web.OtherStuff.MyNameSpace, it's just MyNameSpace.. right??

Or is there something else I need to do, tried adding it to my web.config:

                <add namespace="MyNameSpace"/>

 but it didn't like that either...

Thanks for your help with this, appreciating your patience
.Net and Infrastructure Consultant
Look in your project properties - you may need to prepend that using namespace command with what ever you find in the 'default namespace' box on there.

It probably says 'whateveryouprojectiscalled' so your using statement will be more like

using whateveryouprojectiscalled.namespaceasstatedintheclass
lojk.Net and Infrastructure Consultant
by the way, intellisense (and ctrl-space) is your friend here - i often end up trawling through an intellisense because my best intentions of accurate namespacing and text-casing often ends up in a bit of a muddle.


It's not seeming to play ball.

Out of interest when you say look at the project properties, I am just using view - properties then highlighting my site root folder - is this correct? It was set up as a website not a project if that has any bearing...

No evidence of a 'default namespace' box that I can see?

Have tried using the sitename as a precursor to my namespace but my sqiggly red line just moves from under the namespace name to under the sitename.

When I try using intellisense (thanks for tip there) I get a few namespace options {System, ASP, AjaxControlToolkit, Microsoft, MS} but nothing more 'local' feel like I've missed something fundamental here...
lojk.Net and Infrastructure Consultant
If is a website rather than project if memory serves there is a tick box in the project properties somewhere - allows changes to this precompiled site or don't precompile or something like that.. Untick that and it might permit you to go back to the start of this whole thread and add the appcode folder.

A website is not the same thing as a project and the settings window is considerably different, I now understand why you seem bogged down now in web.config land.


Yeh I did think we might not quite be on the same hymn sheet...I should have checked sooner, sorry - it's been interesting though, so do you built websites as 'new project' rather than 'new web site'?

Irritatingly that 'allow changes to this precompiled site ' tickbox has been ticked all along so not sure why i'm having such issues with this app-code folder but it just wont have it.
Might just go to plan b and start a new site - think it'll be simpler that battling with the peculiarities of VS.
lojk.Net and Infrastructure Consultant
I would recommend it - there are a million benefits , the first one is it manages compilation errors much better and adding n-tied methodology is much simpler (my screen shot from earlier will make a lot more sense too).

some of my first sites I created in vs2005 were done as website but once I moved to proper app it all got a whole lot easier to make (bigger more complicated) things work.

Don't drop everything you have but setup a new web project and get to grips with it, you'll find jt super easy to move what you already have into anyways and life will get easier I promise. I went through a similar thread recently with a chap trying to do things the hard way with html tables.. He's converted now and glad I pushed him! Will post that link below when I find it.

As for your original problem, it may be worth persisting but if you only have a few bits done so far, plan b might be a winner - might actually turn into plan a ;-).
lojk.Net and Infrastructure Consultant
Here we go - another highly verbose thread but might put a few things in context



Thanks, I'll do that, and thanks for the post...will have a read now.

Well, I got round the namespace issue by getting rid of it altogether and putting my class in my code-behind so that they we're on one page and knew who each other were (think I've just gone against everything you've been saying but for the sake of everyones sanity i'm willing to gloss over that if you are...just this once).

after all that my stored proceedure doesn't work anyway - not suprised as never built one of those before either ( http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27622780.html how's your SQL)? so back to the drawing board but thanks for all you help working through this - you've kept me sane at least and I'll be giving the 'new project' button a click pretty soon...sounds like the way to go.
lojk.Net and Infrastructure Consultant

Great, glad you got it working, nearly suggested that but didn't for the reason you said ;-)

Am on holiday atm but will skim the new q and help if it hasn't already been sorted.

In development, every day is a school day - you have nothing to lose by trying something new - its fun, I promise!


Great would be glad of some help but don't feel obliged, just asked the moderators to take a look as it's ground to a halt...

Can't believe you're doing this on your holiday!

But thanks, appreciated :O)