C# Blazor server side - access page @attribute in middleware
Solution 1:
Just found a way how to access attribute.
var pages = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == "Solution.Pages" && t.GetCustomAttributes<IPRestrictAttribute>().Any());
var page = pages.FirstOrDefault(t => t.GetCustomAttributes<RouteAttribute>().Any(x => x.Template.Equals(context.Request.Path, StringComparison.OrdinalIgnoreCase)));
var attribute = page?.GetCustomAttributes<IPRestrictAttribute>();
I'm not saying it's optimal code but it's working. Pages variable should be outside middleware as static global...