views:

307

answers:

2

Hello,


Q1 - Asp.Net is able to detect when you change the original files and automatically recompilles the application when next request arrives


A) But it appears that while with Web sites Asp.Net is able to detect changes, regardless of whether they happen in code-behind file (.cs) or in aspx file, with Web projects Asp.Net only detects changes that happen inside aspx file, but it doesn’t detect changes inside .cs files! Why is that?


B) Asp.Net also detects if any new aspx or cs files were added to the website. But, will it upon the next request compile just the added files, or will it recompile all of app’s files?


C) If an application on a web server contains several aspx files, some created by web project ( and thus their code behind files are inside single assembly ) while other aspx files were created via a website project, how is Asp.Net able to figure out whether particular aspx file has code behind contained within an assembly located in Bin directory?


Q2 “Codebehind attribute is used only by the Visual Studio Web Forms Designer. The attribute is not used at run time.”

  • I assume CodeBehind attribute is not used at runtime due to the fact that all .cs files are compiled into single assembly, and thus VS has no problem locating a class as long as aspx tells the name of the class via Inherits attribute?!

  • On the other hand, Asp.Net code behind model does need src attribute, because here cs files get compiled into separate assemblies and thus asp.net needs to know the name of the file specified by CodeFile attribute, so it can somehow figure out the name of the assembly into which this file compiled?


thanx

+2  A: 

Q1 a: this is because websites dynamically compile and web applications are explicitly compiled. See This article for a table that compares the two types.

Q1 b: By default the everything will recompile. However, there is a hotfix for .net 3.5 sp1 (Knowledgebase article, downloads) released that allows you to choose if you want everything to recompile or if you want only the changed files to compile.

Jimmie R. Houts
+1  A: 

ASP.NET only looks for a code behind file if it can't find the type it needs to complete the compilation of a ASPX in the existing assemblies. A dependancy on the code behind cs file is only created if it was needed when building the temporary assembly for the ASPX file.

Therefore where in a web project all the codebehind cs files are compiled into a single assembly the compilation of a temporary assembly for the ASPX does not require the code behind cs, since the type(s) needed are already present in the pre-built assembly. Hence no dependancy is created between the temporary assembly and the cs file so changing the cs file does not invalidate the existing temporary assembly. Note in deployment the cs files won't even be present.

In a web site there is no pre-built assembly containing all the types in code-behind, hence the code-behind file is required to complete the temporary assembly for an ASPX, in turn a dependancy on the cs file is added to that temporary assembly. Hence any change to the cs file invalidates the temporary assembly.

AnthonyWJones
thank you both for your helpPS - sorry for not replying sooner, but I wasn't home
SourceC