I understand that Web Site Projects compile source on-the-fly, and Web Application Projects pre-compile source into a DLL (much like ASP.Net 1.x).
But how is the difference specified in IIS?
I know that Visual Studio knows -- there are different projects for each, etc. But the running instance (IIS + Framework) has to know which compilation model is being used, right? Because how else does it know whether or not to compile on-the-fly?
A request comes in, hits an ASPX file...and how does the process know whether the associated CS file needs to be compiled (Web Site), or if it was already done before deployment (Web Application)?
I'm just curious where this difference is specified. In the web.config somewhere?
There is a subtle difference in the .aspx file that you'll find in these project types.
If you look at a Web Site Project you should see something like this...
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
... where as the Web Application project will have .aspx files with something like this...
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
Notice that the first has a CodeFile attribute, and the second as a CodeBehind attribute. This is where the distinction is made.
The CodeBehind attribute is NOT used at runtime - it's there to tell VS.NET where the code lives, and the Inherits attribute tells the runtime which class to go searching for in the binaries.
The CodeFile attribute IS used at runtime, and is used by the aspnet_compiler.exe to generate code, and then the Inherits attribute is used as above.
For more info on these attributes, look here...
http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx
But to answer your question "how does IIS know?" the answer is "it doesn't." ASP.NET knows.
You can prove that this is the case by doing the following:
Add the following code into Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("hello");
}
Compile the project, run it, see the text "hello" appear in a browser.
Now, change the code so it looks like this, and save the .cs file:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("goodbye");
}
DO NOT COMPILE. Refresh your browser. You'll still see "hello" because the compiled code still uses this string.
Now, change the attrib in Default.aspx from CodeBehind to CodeFile. Save this file.
Refresh your browser. You'll see "goodbye" displayed.
Change "goodbye" in your code to "I believe!". Save the .aspx.cs but don't compile.
Refresh your browser, see "I believe!", and dance around the room enlightend :-)
All IIS does is pass the incoming request to the appropriate handler. In the case of an ASP.NET site/application it is aspnet_isapi.dll. The handler then takes care of everything from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With