简体   繁体   English

预编译 ASP.NET Webforms 站点以供 IIS 提供服务

[英]Precompiling an ASP.NET Webforms site for serving by IIS

I have a Windows Server 2019 Datacenter edition running in an Amazon EC2 instance.我有一个在 Amazon EC2 实例中运行的 Windows Server 2019 Datacenter 版本。 I am running several applications in IIS (each is configured as a site, rather than a virtual directory application).我在 IIS 中运行多个应用程序(每个都配置为站点,而不是虚拟目录应用程序)。 For example, I may have one application/site called "abc.mycompany.com" and another called "xyz.mycompany.com".例如,我可能有一个名为“abc.mycompany.com”的应用程序/站点和另一个名为“xyz.mycompany.com”的应用程序/站点。

I am attempting to pre-compile each site using "aspnet_compiler.exe".我正在尝试使用“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.我需要 IIS 才能找到已编译的文件夹。

However, when I use "aspnet_compiler" from the command line it compiles to the following folder:但是,当我从命令行使用“aspnet_compiler”时,它会编译到以下文件夹:

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.因此,IIS 找不到正确的文件夹,必须重新编译。

The command I am executing in PowerShell is:我在 PowerShell 中执行的命令是:

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.我知道 EXE 有一个位置参数,但很难猜测这将是什么。 Isn't there a way to call the EXE the same way it's called when the site is accessed for the first time?难道没有办法像第一次访问网站时那样调用 EXE 吗?

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".看起来我需要找到 IIS 站点 ID,然后使用“aspnet_compiler”的“-m”参数。 My PowerShell solution looks like this:我的 PowerShell 解决方案如下所示:

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.希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM