views:

279

answers:

3
  1. Since all files in a web project are compiled into single assembly, then does this assembly maintain a directory structure? For example, if a file in a root directory references a file in a subdirectory, then how could this reference still be valid when the two files get compiled into same assembly?

  2. Assume a web project has the directory structure shown below. Since all of web project’s ASPX files get compiled into a single assembly WebProject1.dll, how is this assembly able to record/memorize the directory structure? Thus, when you deploy WebProject1.dll to a web server and user makes a request for http://WebProject1/some_SubDir/default.aspx, how will WebProject1.dll be able to figure out which Page to render?

    WebProject1\SubDir (where WebProject1 is a root directory) WebProject1 -- contains several ASPX files WebProject1\SubDir -- contains a file default1.aspx.

  3. When we deploy the Web project, must we create the same directory structure on a web server (WebProject1\SubDir), even though we won’t put any ASPX files into those directories?

  4. I assume that on Web server WebProject1.dll should be placed into the Bin directory?

thanx


EDIT:


Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server.

My book says that when using Web project all web code is compiled into single assembly. I thought “all code” includes aspx files?!


Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure

<%@ Page language="c#" Codebehind="default1.aspx.cs" Inherits="WebProject1.some_SubDir.default1" %>

So if I add a new aspx page via Project --> Add New Item, and store this aspx page in a subdirectory named Hey, then this page will reside in namespace WebProject1.Hey?!

But how do I do add new item into a subdirectory, since Project --> Add New Item doesn’t give me an option to browse and choose a directory I wish to save it in, but instead automatically creates aspx file in a root directory?


The relative path is kept when the compiler generate the dll.

I’m not sure I know what relative path you’re referring to?


thanx

+1  A: 

All those path information will be embedded as Meta Data/resource file, so, you can deploy it safely to the server. The relative path is kept when the compiler generate the dll.

I suggest you use Reflector to open the dll, and you can get a much more deeper understanding what is inside dll.

J.W.
+2  A: 

Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server. For example you project in Visual Studio may look like the following:

WebProject1 (The root project)
  |
  |- some_SubDir (A physical directory inside the project)
      |
      |-default1.aspx
      |-default1.aspx.cs (assuming a C# project)

Once you have compiled the web app you'll need to upload the following to the server:

WebProject1 (The root directory for your website)
 |
 |-bin (The binary directory created by the build)
    |
    |-WebProject1.dll (The compiled source code of the web app)
 |-some_SubDir
    |
    |-default1.aspx (The file that will map to the URL www.websitename.com/some_subdir/default1.aspx)

Compiled resources (non-sourcecode files that are compiled and stored inside the assembly) are different issue that are addressed in your other question


Edited to add direct answers to the questions:

  1. Not all files are compiled into the assembly, only source code files are. Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure, but it doesn't have to be.

  2. Your default1.aspx file will have in the header something like:

    <%@ Page language="c#" Codebehind="default1.aspx.cs" Inherits="WebProject1.some_SubDir.default1" %>

The inherits line tells the webserver that when a user requests this page it should be processed in conjunction with the source code that defines that class, which it will find inside the compiled assembly. The combination of the physical aspx file and the compiled class will generate standard html which is then passed back to the client.

  1. Yes, you need to create the same directory structure, but you are required to put the aspx files in there.

  2. Yes

(can someone please edit this if they know how to get the list items to number correctly, please?)

Martin Harris
+1  A: 

Notice how some_Subdir/default1.apsx has a 'Inherits' key/value pair in the page declaration?

What this means is that when you make a request for that resource IIS goes 'Ah ha! Asp.Net needs to handle this request! Hey asp.net please return me some html to send down'

Asp.net parses that aspx file and creates a proxy class on the fly that inherits from WebProject1.some_Subdir._Default1. This proxy class then parses out the control tree and html, and kicks off the page life cycle (this is overly simplified, and I'm sure I've missed some details).

So the WebProject1.dll is just the actual C# / VB of your web app, but in concert with the asp.net worker process and the markup you can render html back to a client.

ecoffey