尽管我已经在这里待了一段时间,但这是我第一次提出问题,所以请温柔地对待我.
我正在使用ASP.NET MVC 3
,我想创建一个自定义,Principal
所以我可以存储更多关于当前用户的信息,而不是标准,因此不必经常访问数据库.这是我追求的相当标准的东西.我们先说一下电子邮件地址和用户ID.
我决定将对象存储在缓存中,因为我知道不建议将它存储在会话中.
我也不想继续构建User
对象,所以我想覆盖User
控制器中的对象.所以我可以去User.UserId
保证一些东西.
所以我创建了一个这样的自定义主体:
public class MyPrincipal : IPrincipal
{
public MyPrincipal(IIdentity ident, List<string> roles, string email, Guid userId)
{
this._identity = ident;
this._roles = roles;
this._email = email;
this._userId = userId;
}
IIdentity _identity;
public IIdentity Identity
{
get { return _identity; }
}
private List<string> _roles;
public bool IsInRole(string role)
{
return _roles.Contains(role);
}
private string _email;
public string Email
{
get { return _email; …
Run Code Online (Sandbox Code Playgroud) 假设我有一个包含多个列的数据库.有一个主键,用户.但是还有另一个列,用户名.当一个新的用户名输入数据库时,我想检查以确保它是唯一的.由于已经存在主键,我可能需要对用户名设置约束.
我不知道该怎么做.当我右键单击列名称并显示"索引/键"时,我看到现有主键的"Users_Key",而不是"用户".所以我必须添加像"Username_Keys"这样的东西?当我这样做时,我在对象资源管理器中的任何地方都看不到它.但我确实在"密钥"下看到了Users_Key?
我刚开始使用mvc razor.
我想以红色显示验证错误消息.
这是我的viewmodel.
public class AViewModel
{
[Required(ErrorMessageResourceName = "EmailAddressRequired", ErrorMessageResourceType = typeof(Resources))]
[HomeController.EmailAddressAttribute(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "EmailAddress_RegularExpression_ErrorMessage")]
public string EmailAddress { get; set; }
[HomeController.LocalizedDisplayNameAttribute("Password", NameResourceType = typeof(Resources))]
[Required(ErrorMessageResourceName = "PasswordRequired", ErrorMessageResourceType = typeof(Resources))]
[DataType(DataType.Password)]
public string Password { get; set; }
[HiddenInput(DisplayValue = false)]
public Guid id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的观点看起来像这样:
<div class="left">
@Html.EditorForModel()
<br />
</div>
Run Code Online (Sandbox Code Playgroud)
而我的CSS看起来像这样:
.left { float:left; width:430px; margin:0 -480px 0 0;
padding:0 40px 20px 0; border-right:1px solid #DDD;}
Run Code Online (Sandbox Code Playgroud)
什么需要在CSS中改变? …