我为什么不能这样做?
[Required(ErrorMessage = "*")]
[RegularExpression("^[a-zA-Z0-9_]*$", ErrorMessage = Resources.RegistrationModel.UsernameError)]
public string Username { get; set; }
Run Code Online (Sandbox Code Playgroud)
告诉我的错误信息是什么?
属性参数必须是属性参数类型的常量表达式,typeof表达式或数组创建表达式.
我想将动态变量作为参数传递给我的属性.在这里,我想使用Environment.MachineName,请参阅下面的代码:
public interface IMonitoringViewModelConfiguration : IConfigurationContainer
{
[ConfigurationKey("MonitoringService", Environment.MachineName)]
string ConnectionString { get; }
}
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:错误1属性参数必须是属性参数类型Abc.ServiceBus.Monitoring.ViewModel的常量表达式,typeof表达式或数组创建表达式
为了传递我的Environment.MachineName,是否有尽可能干净的解决方法?
谢谢.
约翰
PS:我发现了一些谈论这个案子的文章,但它已经写成2 - 3年前了.但今天,来自.NET 4.0的clr能提供一些不错的解决方案吗?
我正在尝试为我的控制器设置授权可以执行以下操作:
[Authorize(Roles = "Approver")]
Run Code Online (Sandbox Code Playgroud)
角色的名称如何保存在数据库中,因此我想尝试执行以下操作:
[Authorize(Roles = Settings.Instance.RoleEmployee)]
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
属性参数必须是属性参数类型的常量表达式、typeof 表达式或数组创建表达式
有什么办法解决这个问题吗?