Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey all,
I wrote a class file for my asp.net website.
In my local host, I just created new class file with the visual studio and it created App_Code folder and put the class file there and then I could use the class.
When I tried to do the same on the live website (to create App_Code folder and to put the class file in the folder), the compiler didn't recognized the class and I couldn't use the class.
How can I use the class?
Thank ahead.
Posted

The class file needs to be in the form of a compiled version called dll to be used on the web page.
When you run your website in visual studio, it does the compilation for you.

Just copy the appropriate dlls from the bin folder into your website path.
 
Share this answer
 
Comments
Sandeep Mewara 21-Apr-12 6:15am    
Quite correct but there is a slight addition here. The App_Code folder works much like the Bin folder, except that you can store source code in it instead of compiled code. Thus, Classes in App_Code are accessible directly.
Abhinav S 21-Apr-12 6:43am    
Right thanks.
ori2694 21-Apr-12 6:15am    
But in my local host it works perfect without reference to .dll file.
Abhinav S 21-Apr-12 7:36am    
Make sure you are running this dll against the right version of the framework in IIS.
Espen Harlinn 21-Apr-12 7:26am    
5'ed!
This is a clear example of what happens when you do things without knowing/understanding why it's done in a given way. You saw that VS created an App_Code folder and put the class there, you are trying to do the same on LIVE site! Awesome!

Have a look at this article: Beginner's Guide to ASP.NET Application Folder[^]

If we store any class files (like .cs or .vb), ASP.NET handles files in special ways - compiler compiles them automatically. Putting class file now by creating App_Code will not do anything as its a compile time thing! This article would be a good read for you: Shared Code Folders in ASP.NET Web Site Projects [^]

Avoid doing 'shortcuts' with code changes next time.
 
Share this answer
 
Comments
ori2694 21-Apr-12 6:35am    
I understand it, but when the visual studio try to create the App_Code folder by itself I receive an error that it can't create the folder, this is why I created the folder by myself and it's still doesn't works.
Sandeep Mewara 21-Apr-12 6:57am    
What error? What ASP.NET version your LIVE site is?

Manually creating a folder on live server is not the solution if you get an error on VS. Cannot even call it a workaround. :doh:
ori2694 21-Apr-12 6:59am    
The error is:
"Unable to add folder 'App_Code' to the Web site. Cannot create folder "App_Code"."
I use ASP.Net 4.0
Sandeep Mewara 21-Apr-12 7:29am    
Your solution might be under source control not allowing you to add?

Did you try to do: Right click webproject -> Add ASP.NET folder -> App_Code.
ori2694 21-Apr-12 7:39am    
Yes, I tried to create it in this way but I received the same error.
Start here Web Application Projects versus Web Site Projects[^]

More details on how to set things up:
Shared Code Folders in ASP.NET Web Site Projects[^]
codeSubDirectories Element for compilation (ASP.NET Settings Schema)[^]

You may also find this useful App_Code folder doesn’t work with Web Application Projects (WAPs)[^]


And have a look at Understanding ASP.NET Dynamic Compilation[^]

Depending on how the host is configured you may need to run the IIS worker process under an account with sufficient privileges How to: Run the Worker Process Under a User Account[^]


You may also find the following to be of some interest:
How To Dynamically Add Controls to a Web Page[^]
Dynamic Controls in ASP.NET[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
ori2694 21-Apr-12 7:41am    
I know the difference between WAP WSP, but I have WSP so I need the App_Code folder.
Espen Harlinn 21-Apr-12 7:43am    
Good, then check out that you have the required permissions on the server ...
VJ Reddy 22-Apr-12 20:22pm    
Nice references. 5!
Espen Harlinn 23-Apr-12 3:46am    
Thanks VJ :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900