Mysteries of the App_Code folder
-
I recently converted one of my web apps over to vs2005 (i did this manually as it felt safer and isnt too large ;P) While im very happy with vs2005 i couldnt help notice one oddity... i put all my classes, including my 'basepage' (a page inherited by all other pages with useful functions in it) in the app_code folder. My basepage references some controls in the project (these live in the 'lib' folder). I cannot seem to access the control types in code from the basepage This is clearly something ms have done on purpose, and while i understand the model and logic behind putting your code in the app_code folder i cant seem to find anything to explain why this might be. p.s im aware that i can put the codebehind for my controls in the app_code folder, but that doesnt really explain what im asking. Anyone know? :confused:
---Guy H (;-)---
-
I recently converted one of my web apps over to vs2005 (i did this manually as it felt safer and isnt too large ;P) While im very happy with vs2005 i couldnt help notice one oddity... i put all my classes, including my 'basepage' (a page inherited by all other pages with useful functions in it) in the app_code folder. My basepage references some controls in the project (these live in the 'lib' folder). I cannot seem to access the control types in code from the basepage This is clearly something ms have done on purpose, and while i understand the model and logic behind putting your code in the app_code folder i cant seem to find anything to explain why this might be. p.s im aware that i can put the codebehind for my controls in the app_code folder, but that doesnt really explain what im asking. Anyone know? :confused:
---Guy H (;-)---
There is not anything mystical about the App_Code folder. It's just a good place to put code that is not pages. Code in the folder is not isolated in any way from code outside the folder, so if you have trouble accessing classes it's because you don't use the correct namespace.
--- b { font-weight: normal; }
-
There is not anything mystical about the App_Code folder. It's just a good place to put code that is not pages. Code in the folder is not isolated in any way from code outside the folder, so if you have trouble accessing classes it's because you don't use the correct namespace.
--- b { font-weight: normal; }
but if they are both created within the same web project and i havent added any extra namespaces they should both be in the same namespace right? this was my 1st thought and i searched the object browser etc.. nothing!
---Guy H (;-)---
-
but if they are both created within the same web project and i havent added any extra namespaces they should both be in the same namespace right? this was my 1st thought and i searched the object browser etc.. nothing!
---Guy H (;-)---
Basically, if you want to have code to be compiled, you have to put it in app_code folder. exceptions are only pages (.aspx) and controls (.ascx) with their code behind (AFAIK). You can access code in app_folder from outside of this folder (page can call this code), but you can not access code outside of app_folder from inside (your library cannot access page). If you need to work with any of your pages / controls from app_folder, you have to create interface for it, put this interface into app_folder and your page / control have to implement this interface. Then you can call methods or access properties of your control / page using this interface, which is known to your code (it is in app_code folder). Pilo