ardalis/OrganizingAspNetCore

Handling Razor Pages when mixed with MVC

Aperta

#14 aperta il 31 mag 2018

 (1 commento) (0 reazioni) (0 assegnatari)C# (58 fork)github user discovery
help wanted

Metriche repository

Star
 (210 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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?

Guida contributor