ardalis/OrganizingAspNetCore

Handling Razor Pages when mixed with MVC

开放

#14 创建于 2018年5月31日

 (1 条评论) (0 个反应) (0 位负责人)C# (58 个派生)github user discovery
help wanted

仓库指标

星标
 (210 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Firstly a great library, I've been using your library for a while, and recently with the introduction of ASP.NET 2.1 Identity as a library https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.1&tabs=visual-studio

I noticed that an exception is thrown for Razor Pages

It seems the controller action description is null for razor pages?

if (controllerActionDescriptor == null)
            {
                throw new NullReferenceException("ControllerActionDescriptor cannot be null.");
            }

Am I missing something or should this still be able to work?

UPDATE I was able to solve the issue by using the following line instead

var featureName = controllerActionDescriptor != null ? controllerActionDescriptor.Properties["feature"] as string : string.Empty;

I'm not sure if this is the best way to solve the issue, would be interesting to know how to detect razor controller action

UPDATE2 Looks like **PageActionDescriptor ** can be used to read razor pages https://joonasw.net/view/discovering-actions-and-razor-pages

Further information can be found here: https://github.com/aspnet/Mvc/issues/7796

Maybe this can help in trying to make it better?

贡献者指南