问题
I'm attempting to add a "Restrict" attribute in my AppHost. Here is my code:
var restrictAttribute = new RestrictAttribute { ExternalOnly = true };
foreach (var dto in dtos)
{
dto .AddAttributes(restrictAttribute);
}
The DTOs I'm adding them to are ones specifically for POST requests.
The problem I'm facing is that after adding the attributes dynamically, the ServiceStack functionality for the restrict doesn't work. It DOES add the attribute, but doesn't actually restrict anything.
The only way I can make this work is by adding the Restrict Attribute in the Request DTO manually. Am I doing something wrong here?
回答1:
For dynamically adding Service Attributes you need to add them before AppHost.Configure()
since they're already initialized by the time Configure()
is run, so they need to be either added in AppHost constructor or before AppHost.Init()
is called.
来源:https://stackoverflow.com/questions/36403300/dynamically-adding-attributes-in-servicestack