user3887998
user3887998

Reputation: 21

Precompiling an ASP.NET Webforms site for serving by IIS

I have a Windows Server 2019 Datacenter edition running in an Amazon EC2 instance. I am running several applications in IIS (each is configured as a site, rather than a virtual directory application). For example, I may have one application/site called "abc.mycompany.com" and another called "xyz.mycompany.com".

I am attempting to pre-compile each site using "aspnet_compiler.exe". I would like to compile each site exactly the same way it would be compiled when someone hits the site for the first time. I need IIS to be able to locate the compiled folder.

However, when I use "aspnet_compiler" from the command line it compiles to the following folder:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\43ab1102\aee092a7

When the site is compiled on first access by a user, it compiles to this folder:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\7bb02463\3efd21b2

Notice the last two sub-folders are different. Thus, IIS doesn't find the correct folder and must re-compile it.

The command I am executing in PowerShell is:

Set-Location -Path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
.\aspnet_compiler -v / -p "C:\inetpub\abc.mycompany.com"

How can I get this command to compile to the correct folder? I know there is a location parameter for the EXE, but its hard to guess what this is going to be. Isn't there a way to call the EXE the same way it's called when the site is accessed for the first time?

Upvotes: 1

Views: 866

Answers (1)

user3887998
user3887998

Reputation: 21

I think I just figured this out. Looks like I need to find the IIS site ID and then use the "-m" parameter of the "aspnet_compiler". My PowerShell solution looks like this:

Set-Location -Path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
$siteId = Get-Website -Name "abc.mycompany.com" | Select -ExpandProperty ID
.\aspnet_compiler -m /LM/W3SVC/$siteId/ROOT

Hope this helps someone else.

Upvotes: 1

Related Questions