It depends on the type of project. With ASP.Net, you can create two types of projects: Web application project and website project. .
How the .aspx and aspx.cs file is compiled
With the Web Application project, you compile the code behind the aspx files, user controls, and other code found in this project into one single dll and deploy it to the server.
With the Web Site Project you simply copy the source code to the server, and ASP .Net handle the compilation for you. The website project contains the source code for custom classes in the App_Code folder (you will need to learn more about this at this link)
Will there be two assemblies or both of these files will be merged into one and will be created as one assembly?
In any of these cases, the code found in the aspx, ascx is not compiled by you (using Visual Studio, etc.). ASP .Net analyzes these files and creates a DLL stored in its temporary folder. "DLL aspx, ascx" (there can be more than one), these are different files than those that you created using Visual Studio (and I believe that this is different from the one that was created from the App_Code folder, because this code does not maybe the access code found on the pages).
Is any hierarchy / inheritance consistent?
Yes. When a page is parsed and compiled, this generated class inherits the name specified in the "Inherits" attribute found in the @Page directive.
<%@ Page Language="C#" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
ASP.Net parses the Default.aspx file and generates a class that inherits WebApplication1._Default
public class default_aspx : global::WebApplication1._Default { }
Given that the generated class from markup inherits the class we wrote (usually the one that is in the code, the aspx.cs file), we can use its members or methods.
The following method is the _Default class method:
protected string ToUpper(string source) { return source.ToUpper(); }
Then in the markup we can call:
<form id="form1" runat="server"> <%= ToUpper("Microsoft") %> </form>
We can even write in the markup something like:
<% SomeValue = 1; %> <%= SomeValue %>
Where SomeValue is at least a protected property of the _Default class.
We can also declare participants and write server code in the markup:
<head runat="server"> <script runat="server" language="C#"> private int someCounter = 10; </script> </head> <body> <% for (var i = 0; i < someCounter; i++) { %> <p> Paragraph number:<%= i %> </p> <% } %> </body> </html>
Here I declare the someCounter field and use it to write 10 paragraphs. Of course, this is not the recommended way to do such things. Since someCounter is a member of the generated class, this is not available in the code behind.
There is another huge (and more real) advantage of this architecture. Suppose that some pages on a website are kind of static (about.aspx, privacy.aspx, etc.), They use the same main page. The code located on these pages does not change. This means that we can create other pages and deploy them without having to compile another code (this aspect applies to web application projects). In addition, before we go live, we can only allow one person to see these pages. Therefore, to achieve this, we create the PreviewPage class
public PreviewPage: System.Web.Page { public PreviewPage() { this.Load += (o, e) => {
And change the value of Inherits :
<%@ Page Language="C#" Inherits="WebApplication1.PreviewPage" %>
aspx is created as the corresponding c # code file
The Language attribute in the @Page directive determines which language is used to compile the aspx/ascx . This way you can use VB.Net in your aspx file and compile the site using the C # compiler.
This is another compilation, different from the one in Visual Studio, with different parameters. This is why web.config has options for setting compilationMode to Debug/Release , as well as for telling the compiler to use other available options.