首页 文章

ASP.NET核心中的Request.CurrentExecutionFilePath

提问于
浏览
0

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

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

相关问题