ardalis/OrganizingAspNetCore

Handling Razor Pages when mixed with MVC

オープン

#14 opened on 2018/05/31

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C# (58 件のフォーク)github user discovery
help wanted

Repository metrics

Stars
 (210 個のスター)
PR merge metrics
 (30d に merged 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?

コントリビューターガイド