How to Run Asp.net website project as a web Application Project

Emeka Okoye 86 Reputation points
2024-06-17T13:06:17.44+00:00

Hello,

I have just assumed a duty to take over development of a asp.net project.

It happened that the project is a asp.net website project, and I discovered the the former developer did not create App_code folder, when I brought the solution to my VS development environment, all the asp.net elements, textboxes, tables, labels were not recognized, and there were no page designer for each page, and these made it impossible for the solution to be compiled.

I have tried to convert to solution to a asp.net web application project. with that some of the element were recognized, but a whole lot of them are still unrecognized.

I need some advice on how to resolve this issue, what can I do to make the elements to be recognized in the solution, as the former project developer is no where to be found to get help from him.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,394 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,562 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 60,201 Reputation points
    2024-06-17T17:11:51.9233333+00:00

    with an asp.net website:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>

    the aspx and it code file are deployed and compiled on the website. because of the aspx file is compiled first, then the partial, no designer file is required. no project file is required.

    with asp.net application:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Index" %>

    the code behind files are compiled and built into a binary deployed with the site. the aspx are compiled later. because of this a designer file is required because the code behind does not know about any of the runat="server" controls defined in the aspx file. visual studio maintain a definition of these controls in the code behind. a project file is required.

    to convert a website to web application is a bit of work. create a new empty web application. then add all the website files to the application. then at the project level (or via feature search) pick "convert to web application". this will update codefile= and add designer files.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Albert Kallal 5,226 Reputation points
    2024-06-17T19:03:17.2933333+00:00

    You have some good answers.

    As pointed out, try using file->open web site, and then see if the project can build + run.

    The fact of no app_code? That's actually a VERY good thing and that VERY much suggests that this may well have been a "application". However, even with a "application", I now NEVER use App_code.

    Why?

    Well, while with a "application", Visual Studio now does the code compile, and NOT IS.

    However, one bad exception is IIS will still often, it not in most cases compile the App_Code folder for you. This turns out often to be a huge issue, since now IIS is STILL compiling code, even when using a "application". That means a .exe and the Roslyn compiler extension ALSO have to be deployed to the production server, often of which is it some hosting plan, and those plans often make it VERY difficult to deploy and include the Roslyn compiler extensions, and especially .exe files.

    As a result, for "applications", I create a folder called MyCode. Then as you drop each code module/class etc. into that folder, you right click, and select the build option to compile. That way, I can then during a publish select pre-compile, and thus if the target server or hosting plan does not have Roslyn extensions installed, it does not matter. it also means that IIS is NEVER compiling your code. NEVER!

    So, the missing App_code folder? Are you sure you have the source code files here? You have both the .aspx files, and you have the .aspx.vb or the aspx.cs files then?

    In other words, the designer files are never published to the server anyway. With a application, then ONLY the aspx files are published, and no source code files (.cs, or .vb, and the designer files) are NEVER published either.

    This means with only .aspx pages, then you don't have the source code for the site to work on this project.

    Of course, if using a "application", then no app code folder is required, and no source code files is are required to be published to the server.

    And, as noted, assuming you have a "web site" and not "web site application"?

    Then you must open the project using file->open web site, and then browse to the folder, and at that point, you should be able to use the build option, and as pointed out, such projects don't have .designer files, and they NEVER did. So, lack of designer files should not prevent you from using the designer here at all.

    So, first up is to be 100%, 200%, and 300% sure that you have source code for each page, and that you have a "web site" as opposed to a "web site application". So, for each .aspx page, do you have the corresponding "vb" or the "cs" file? This you MUST make sure you have.

    next up?

    Conversion to a application is VERY much recommended, but that is a huge step, and ONLY a step to be taken AFTER you can have a known working and are able to build the existing web site. In other words, you don't want to deal with 2 significant issues at the same time. That means if you going to spend the time and efforts converting to a "application"? (and I think in most cases this time and effort is worth it).

    Then first step before undergoing such a conversion and migration is to have a known working web site that builds. You NEVER want to start the conversion to a "application" without first having a known and working site that that builds. If that web site can't build, does not build, then you want to deal with the conversion to a application as a separate step, and a step that occurs only AFTER you have a known and working web site that builds in the first place.

    So, right now, you have to ensure that web site builds. Designer files are not required, but for each web page, the .cs, or the .vb files are required for each page, and you can even still use "design mode" from Visual Studio - hence designer files don't prevent you from using the web page design mode from Visual Studio, and lack of .designer files NEVER prevented you from using the web page designer from VS anyway.

    So, top goal is to use file->open web site, and get the site to build. Once it builds, then you can take on the next challenge of converting to a "application". Do not attempt doing both tasks at the same time (getting site to build + run, and that of converting each page to work as a "application".

    0 comments No comments