我在我的 ASP.NET WebForms 应用程序中使用路由,使用 Phil Haack 描述的技术:
这在大多数情况下运行良好,但有时第一次调用System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath
is 需要数十秒才能返回。
这发生在以下方法中:
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
LapTimer lapTimer = new LapTimer();
string virtualPath = this.GetSubstitutedVirtualPath(requestContext, lapTimer);
if (this.CheckPhysicalUrlAccess && !UrlAuthorizationModule.CheckUrlAccessForPrincipal(virtualPath, requestContext.HttpContext.User, requestContext.HttpContext.Request.HttpMethod))
throw new SecurityException();
IHttpHandler page = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page)) as IHttpHandler;
if (page != null)
{
//Pages that don't implement IRoutablePage won't have the RequestContext
//available to them. Can't generate outgoing routing URLs without that context.
var routablePage = page as IRoutablePage;
if (routablePage != null)
routablePage.RequestContext = requestContext;
}
return page;
}
与此同时,我注意到(使用任务管理器)一个名为csc.exe的 C# 编译器进程占用了我 10%-50% 的 CPU。
谁能建议为什么会发生这种情况?