ASP.NET核心中的Request.CurrentExecutionFilePath

问题描述 投票:0回答:1

我目前正在使用https://github.com/madskristensen/vswebessentials.com/blob/master/Website/Views/_Layout.cshtml在“旧”Razor应用程序中的方法。在移植到Core 2.1时,我没有找到Request.CurrentExecutionFilePath的等价物(我打算发布MvcRazorCompileOnPublish设置为false,因此cshtml文件将用于缓存失效)

asp.net-core razor-pages
1个回答
0
投票

您可以使用IPageFilter OnPageHandlerSelected方法访问当前页面的ActionDescriptor。它公开了一个RelativePath属性,它为您提供当前页面的相对文件路径:

public override void OnPageHandlerSelected(PageHandlerSelectedContext context)
{
    var file = context.ActionDescriptor.RelativePath;
}

你可以在这里阅读更多关于IPageFilter及其方法的信息:https://www.learnrazorpages.com/razor-pages/filters

© www.soinside.com 2019 - 2024. All rights reserved.