This question came up in one of my Web development courses and I thought it was interesting to discuss it here.
As you know ASP.NET uses some auto-generated code files to “mix” its code with the “code-beside” classes which contain the events and the written code for the Web forms, using partial classes and inheritance.
Note: For example, the “code-beside” file for Default.aspx is Default.aspx.cs or Default.aspx.vb depending on the chosen programming language, C# or VB.
This code is generated dynamically when the Web site is compiled and, at least theoretically, it’s stored for caching in the folder:
C:\Windows\Microsoft.NET\Framework\vx.y.zzzz\Temporary ASP.NET Files
being x.y.zzzz the version of the platform we have installed, “v4.0.30319″ for .NET 4.0 and “v2.0.50727″ for previous versions (2.0, 3.0 and 3.5) (versions 2.0, 3.0 and 3.5 are exactly the same as far as ASP.NET is concerned).
The files have random names so we have to look inside each one, but in small applications it is very easy to locate specific parts and forms and see their function:
The thing is that if we run a Web application from Visual Studio, it is very interesting to take a look at these files to see how they work:
What we can actually see in these files is the Web Form inner workings. We can learn a lot and I encourage my students to take a look at them.
Why is my “Temporary ASP.NET Files” folder empty?
The problem is that this does not seem to work in Windows Vista and Windows 7 so if you go to this folder, it probably will be empty. This is not the case in Windows XP.
The reason is that this folder is used for caching the compilation but it’s not required. So if there is no access, the application will be compiled in memory each time, period.
In Windows Vista/7 even if you’ve logged using an administrator account, you will actually run the process with limited permissions for security. So when you attempt to execute something that requires more privileges you’ll get a modal system window asking for permission.
Temporary ASP.NET files folder requires write permission. If you log as administrator and execute Visual Studio just by clicking its shortcut, you are actually executing it as a regular user. That’s why the folder is empty when compiling: you have no permissions.
But if you execute Visual Studio as administrator:
This is, right-click in its shortcut and select the option as in the image.
In this case you’ll have access to the folder and now you are able to see how the temporary files are saved.
Take a look at them. You’ll learn a lot about the ASP.NET inner workings.
Change the location of the temp folder
If you want you can change the location of this temp folder to any other in your hard disk, applying other permissions and therefore accessible for a regular user.
You only have to change the tempDirectory attribute in the compilation element in the Web.config, for example:
With this the files will be readily available so you can research and learn. I do not recomend it for production applications.
I hope this is helpful!