reference app_code classes in web application project - asp.net

I have created an asp.net website, with the accompanying app_code folder.
In the same solution I added a web application project, and I want to use the classes that are in the website app_code folder.
I tried adding a reference, and then adding the project (the website), but the list of project is empty...
Thanks.

You are doing it wrong. Create a class library project and move all those classes from the app_code folder to the new project. Then reference this project from both website and web application project.

Very late, but sometimes classes in App_Code may need to stay in the same project, then
Create a new folder (say "code" )in web application, and add class files from app_code as links to this folder. This lets you have a single copy.
2) Ensure Build Action for each of these imported files are "Compile" in the file property folder if need be.
3) Exclude App_Code folder from web application.
More information and reasons - please see here:
http://vishaljoshi.blogspot.in/2009/07/appcode-folder-doesnt-work-with-web.html

Related

Howto add and link to existing WebSite project from ASP.NET project

I have an existing Website project; its just one .html and a bunch of .js files (all client-side stuff). This project only has a .sln file, no *.*proj files. It's directory structure is basically:
WEB_PROJECT_ROOT/apps/foo/index.html
WEB_PROJECT_ROOT/lib/*.js
Now I'm working on a new ASP.NET Forms Application, and I need to link to index.html page above, but I'd like to keep it as a separate project (and not just copy it into the new ASP.NET project). It's structure is basically:
APP_PROJECT_ROOT/Pages/*.aspx
I've done Add -> Existing Project and chosen the .sln from above, and it shows up in the ASP.NET solution, but I can't figure out how to link to index.html because it's outside of the ASP.NET project's ~/ directory. Is there are way to symlink to it somehow? Or something else?

ASP.NET App_Code in folder

I am working on a ASP.NET VB project. The host is pretty restrictive, so the App_Code folder has to be placed under the wwwroot folder.
My current folder structure (on the server) looks like this:
root
<-- Cant create folders or files here, host is restrictive.
wwwroot
App_Code
Class.VB
Styles
style.css
default.aspx
web.config
It seems to be working, if Class.vb contains errors, i get a compilation error on the website, so i know its compiling the class.
But i am unable to use the class in my other code files.
Example:
Dim emailFilter As Validation = New Validation()
I get this error in VS2010:
Type 'Validation' is not defined
How do i use the App_Code folder when its inside another folder?
Could it be an issue with namespaces? I might be more inclined to create a library for your validation class and add a reference to it instead.
I did find some similar issues to yours and they all referenced setting the Build Action for the class to 'compile'.
Classes residing in App_Code is not accessible

How can I change any app code class after publishing the website?

I upload the website after publishing it, now I want to change a line of code in a class which resides in app_code folder. After changes I again publish the website and upload the new app_code.dll to replace the old one but its not working. The whole functionality of app_code is not working. Is there anybody to solve my problem? thanx in advance.
The App_Code folder will parse any source files you drop in there, e.g. MyClass.vb or MyClass.cs. If you are compiling classes into a DLL, you want to put the DLL file into the bin folder instead.
If the classes are contained in your project and have their build action set to compile, they will automatically be compiled into the web application's DLL when you run a build, and should update every time you publish the site as a publish automatically builds the project/solution.

two problems with Web Site type project (not Web Application)

I have a project which is a Web Site, not Web Application and have two problems because of that.
I have a custom control derived from BaseValidator which I had to put in the App_Code folder. Now on the page I want to register this control by
<%# Register tagname="mytagname" Namespace="PP" TagPrefix="dv2" %>
But when I get enter to this page, I have exception, because the src attribute is missing. I can't put in the src attr. path to the App_Code because I have another exception. How can I do that? This is a Web Site, so the sources are not compiled to one dll file, so I don't know what to add to the src attribute.
When I want to add to the Web Site a new project library, I have to compile it and manually copy the library dll file to the bin folder in the Web Site. But don't know, how can I debug this library with brakepoints?
This is my first time with Web Site project type. I always created the Web App.
1- Don't use tagname attribute here, tagname is suitable for UserControls.
http://msdn.microsoft.com/en-us/library/c76dd5k1.aspx
2- There is no any difference between using library in a web app or website. Just choose Add Reference from project node's context menu and select your class library from project tab.
Try creating a separate project for your CustomControls and reference it in your WebSite project by the namespace you use in your CutomControls project. Also check out this post for some information asp.net add custom control in website
Your second question, if you keep all of your projects in the same solution and just reference them to each other's projects, you will be able to debug and step into methods and set break points in any of the projects in your solution. If you don't want to do that, you have to copy the debug symbol files along with the .dll to the bin or point VS to where the necessary debug symbol files are located and then you will be able to step through the code in the .dll

consuming classes from folder other than App_Code

I am creating a site wherein I have a folder which contains some .cs files. I want to access those classes in .aspx and .ascx files. I’ve created some properties in it, but when I create the object of the class I don’t find that property via IntelliSense.
How can I use and consume those properties from that .cs file?
The website will only compile code files that are in the App_Code folder or are codebehind files for referenced controls. There isn't a way to reference classes defined in code files outside of the App_Code folder.
If you compile those classes and put the resulting dll in your website's bin folder, then you can reference them. To do that, you'll need to add them to a Web Application project in Visual Studio. See Ian Robinson's WAP blog post for most details.
Just have those properties public and you'll see them.
If still no luck please post your code and also tell: can you create instance of the class without error? Can you access any other properties or methods?

Resources