Unique Id for .Net Core actions

I need to have an ID for my actions to save them in DB and retrieve them for security issues. I thought this is a unique and constant Id but it is different in every run:

var items = _actionDescriptorCollectionProvider
                  .ActionDescriptors.Items
                  .OfType<ControllerActionDescriptor>()
                    .Select(a => new
                    {
                        a.ControllerName,
                        a.ActionName,
                        a.Id               
                    })

Any idea for a unique and fixed ID for each action?

1 answer

  • answered 2021-04-21 19:05 Xerillio

    How about:

    _actionDescriptorCollectionProvider
        .ActionDescriptors.Items
        .OfType<ControllerActionDescriptor>()
        .Select(a => new
        {
            ControllerName = a.ControllerTypeInfo.FullName,
            ActionName = a.ActionName,
            ParameterTypes = a.Parameters
                .Select(p => p.ParameterType.Name) // Or FullName to be safe
                .ToList()
        });
    

    I think that should be unique enough.