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.
Related
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 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();
When I publish any type of asp.net application, my code is precompiled into various assemblies. I would like to avoid this so that I can upload an aspx page and its corresponding codebehind file. I understand the benefits of doing it either way, but what is desired here is the least risky way to publish changes.
How does one properly deploy an asp.net project without compiling assemblies?
Is the process different for each model (web app, MVC..)
Sounds like you have a Web Application Project, and what you want is a Website Project. With website projects, you can modify the aspx and codebehind files and not have to worry about recompliling them, asp.net will do that for you. Web Application Projects need to be compiled for every code change.
Can I somehow utilize the App_code folder in a web application project to compile code on the fly? It'd be great for plugins. Recently Rob Conery demonstrated its use in his talk at MIX 09 in a ASP.NET MVC app. I tried to do the same in a web app but I can't access the classes under App_Code from anywhere else. But if Rob was able to do it in an MVC app, it should be doable in a web application too. After all ASP.NET MVC IS a ASP.NET Web Application under the covers.
If you add a code file to the App_Code folder, it should be compiled and available from a code-behind file for a control, or another code file in the App_Code file.
I don't think you'll be able to access it directly from a compiled assembly, since the compiler won't be able to find that reference at compile time.
You'll also need to be aware that App_Code is compiled into a different assembly than your code-behind code, so you can't access internal code across the different assemblies.
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?