I have inherited a code base that does not compile properly. The project is a Visual Studio 2005 web site. I want to move it to a web application. The first thing I am trying to do is move the "App_Code" directory over. The pages in the application rely on some class objects that are defined in the "App_Code" directory.
Visual Studio 2005 does not directly give you the ability to add a "App_Code" directory. Because of this, I manually created one. I then placed the class definitions in this directory. I then compiled the web application.
Next I attempted to migrate the Default.aspx page. This page derives from a class called GenericPage defined in the App_Code directory. However, I cannot seem to reference this class. The definition does not use any namespaces. Where does this code get stored? How do I reference it?
Thank you!
Maybe this tutorial is helpful: Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio 2005
I'm reading at various places that the App_Code folder should not be used in Web Application Projects. See also this SO question: App_Code folder issues
The solution given in that last link is:
Create a new folder called code or
something and put them in there.
More info here:
Automatic reference of class files inside App_Code vs reference of class files outside App_Code
You might have to try grabbing it by using the global namespace.
Example:
var somePage = new global::DefaultNamespaceForProject.PageICantFind();
Related
I have one quesion, let's put I have a project with 3 web forms and each form has inside 5 connection strings or any other static variable so total would be 15.
And let's assume that I can't deploy the dll because I am told to use aspx.cs and aspx files only.
If I don't want neither store the connection string inside the web.config I can create a normal class (no aspx.cs only class.cs) where I create a static Constant for using it in my classes.
In the end I have 3 aspx.cs files, 3 aspx and one cs, but if in the IDE it works when I deploy it says "couldn't find reference to Class."
Why is that? It would be very useful for storing variables.
There are two ASP.NET project types:
Web Application Projects: Here, the code in aspx.cs and .cs files is compiled into a DLL. If you cannot deploy the DLL, you cannot use this project type.
Web Site Projects: That seems to be what you are looking for. The code is compiled at run time; you just need to make sure that your shared code (your .cs file) is located in the App_Code folder.
If you project is currently a web application project, you need to change it to a web site project or change the opinion of the person who told you not to use DLLs.
When you deploy using the Web Site project model, the class files (.cs) need to be placed in a special folder called App_Code.
I've created a new ASP.NET Web Site in VS2008. I'm attempting to rebuild an old VS.NET application (.NET 1.0). I imported all of the WebForms from the old project (Add Existing items) and I ended up with a ton of errors like:
"The name 'lblMessage' does not exist in the current context"
The partial classes in this project don't have the object definitions for each of the UI elements. I'm hoping there's a way to generate these without having to try to hand-code 500 object definitions.
I ultimately found a workaround for this issue. By manually creating the designer pages ('mypage.aspx.designer.cs') file and then performing an edit on the markup page ('mypage.aspx') Visual Studio will automatically rebuild all the references.
Try to use ConvertToWebApplication in Context Menu , WebApplication project file.
This will Generated aspx.designer.cs with declaration for controls.
I am migrating my web site to web application and not sure where to put app_code files? I have moved the whole app_code folder to web application but while compiling web app I get error that classes are not found.
I think once an Web Application, the App_Code folder is relatively useless...as in, it doesn't have its special meaning that it has within a WebSite project. So there's nothing stopping you still having a folder called App_Code and putting your classes (and whatever other files) in there.
It may make more sense to put the files within folders and namespace the classes with relevance logical groupings (helper classes, business rules, data access, whatever) or perhaps move the classes into a separate Windows Class Library project (DLL) which your web application references...
I just found that I must mark files inside app_code as compile and everything will work.
I'd like to add nunit testing to a VS2005 C# ASP.NET website project - so that I can excercise methods in the App_Code directory.
It's recommended that the tests are added as a seperate assembly so that the testing code does not get delivered with the website - in this lies my question:
When I add a new project into the solution which holds the website and try to add a reference to the website project it does not show up in the projects tab - is it possible to reference a website project from another project (without having to convert the website project into a web application project)?
I would recommend you to extract the classes you have in your App_Code folder and place them in a separate project. Reference that new project in your web project. You will now have a better separation of your projects and classes, and can unit test your classes separately.
I have a web app that I wanted copy to a new project.
I created the new app with VS2003 and copied across the web forms, config, global asa, etc. and made sure IIS says it is a web app.
However, I still get this error when I run the app using IE from VS IDE:
ASP.NET v1.1 Could not load type TBRWEB.frmLogin
I also made sure the assembly name and root namespace are the same as original.
Any ideas?
These error normally occurs if the .aspx page or the Global.asax page contains a reference to a code-behind module and if the application has not been built.
Look in your project settings and check the value of the default namespace (in the application section).
Then check the "inherits" attribute in the control header of your ascx control (and yll other aspx/ascx files). I suspect that these two names are not the same. Creating a new project maybe you choose a different name which became the default namespace.
The simplest solution would be to change the namespace of your project to TBRWEB, if that is an option.
if it is not that easy, then my follow-up questions are:
Did you successfully build (compile) the application?
If it's a ASP.NET web site (not web project), did you forget to copy the .cs/.vb files in the App_Code folder?