App_Code and server

I have a "tiny" problem with my App_Code folders.

I am learning ASP.NET and therefore ordering a web server with support for ASP.NET 4.0. I use Visual Web Developer to program my web pages. When I upload my site to this web server, everything works fine.

However, if I then add another web project to my server, my App_Code folder becomes messy. The server wants all my class files in the App_Code folder in the root. Is there a way to create subdirectories in my App_Code folder or something to organize my projects or did I skip the item here?

+4
source share
4 answers

You should take a look at codeSubDirectories in web.config

+2
source

Ok, I found a solution to my problem. Although most of your answers may also work, this turned out to be the best in my case. I created a subdomain and dropped all the files in this folder and it worked fine.

+1
source

If you have access to the hosting control panel, it is best to set up your hosting environment with a virtual folder for your second website and start it from a subfolder, for example. www.example.com/ Project b . The first site can still work in the root folder, for example. www.example.com.

Thus, both sites will be essentially isolated from each other (just as they are now isolated as two separate projects in Visual Web Developer Express). And both sites have their own App_Code folder (and web.config file).

If you do not have access to the configuration panel, most hosting providers are ready to add a virtual folder to you, since this is really not a special requirement.

The virtual folder should appear as a regular folder in your FTP folder, usually in the www or wwwroot folder. Now you can copy the project files to this folder.

Observe the root paths for the URLs in the second project, so all links will work even if the website is launched from a subfolder. The root URLs are as follows:

 <asp:HyperLink runat="server" NavigateUrl="~/Default.aspx" /> <asp:Image runat="server" NavigateUrl="~/images/logo.png" /> 

When you deploy a website in a virtual folder, they will automatically go to www.example.com/project-b/Default.aspx and www.example.com/project-b/images/logo.png .

If you need to reuse code from one site to another, it is usually best to move such code to a separate type of class library project, and then add a link to this project to each website project (right-click the website, select Add link ... ", then select the" Projects "tab and select the" Class Library "project).

0
source

You should try to avoid using the App_Code folder for your own things, especially if you are using a web application project.

Whenever you convert a website into a web application project, the process actually renames the existing App_Code directory to Old_App_Code.

See here , although this is specific for converting .net 2.0 applications, I believe that this is still true in 4.0 since converting a 4.0 application does the same:

VERY, VERY IMPORTANT: since ASP.NET 2.0 tries to dynamically compile any classes that it finds in the / App _Code directory of the application at run time, you explicitly DO NOT want to store the classes that you compile as part of your VS 2005 Web Application Project in the " app_code ". If you do this, the class will be compiled twice - once as part of the VS 2005 web application project assembly, and then again during ASP.NET runtime. The result, most likely, is the “do not load type” exception, caused by the fact that your application has duplicate type names. Instead, you should store the class files in any other directory in your project except one named "app_code". This will be handled automatically using the Convert to Web Application command. This command will rename the Old_App_Code folder.

0
source

Source: https://habr.com/ru/post/1391313/


All Articles