ASP.NET MVC 安全
asp.net mvc - 安全
为了学习 asp.net mvc,我们将构建一个 internet 应用程序。
第 8 部分:添加安全。
mvc 应用程序安全
models 文件夹包含表示应用程序模型的类。
visual web developer 自动创建 accountmodels.cs 文件,该文件包含用于应用程序认证的模型。
accountmodels 包含 logonmodel、changepasswordmodel 和 registermodel:
change password 模型
public class changepasswordmodel
{
[required]
[datatype(datatype.password)]
[display(name = "current password")]
public string oldpassword { get; set; }
[required]
[stringlength(100, errormessage = "the {0} must be at least {2} characters long.", minimumlength = 6)]
[datatype(datatype.password)]
[display(name = "new password")]
public string newpassword { get; set; }
[datatype(datatype.password)]
[display(name = "confirm new password")]
[compare("newpassword", errormessage = "the new password and confirmation password do not match.")]
public string confirmpassword { get; set; }
}
{
[required]
[datatype(datatype.password)]
[display(name = "current password")]
public string oldpassword { get; set; }
[required]
[stringlength(100, errormessage = "the {0} must be at least {2} characters long.", minimumlength = 6)]
[datatype(datatype.password)]
[display(name = "new password")]
public string newpassword { get; set; }
[datatype(datatype.password)]
[display(name = "confirm new password")]
[compare("newpassword", errormessage = "the new password and confirmation password do not match.")]
public string confirmpassword { get; set; }
}
logon 模型
public class logonmodel
{
[required]
[display(name = "user name")]
public string username { get; set; }
[required]
[datatype(datatype.password)]
[display(name = "password")]
public string password { get; set; }
[display(name = "remember me?")]
public bool rememberme { get; set; }
}
{
[required]
[display(name = "user name")]
public string username { get; set; }
[required]
[datatype(datatype.password)]
[display(name = "password")]
public string password { get; set; }
[display(name = "remember me?")]
public bool rememberme { get; set; }
}
register 模型
public class registermodel
{
[required]
[display(name = "user name")]
public string username { get; set; }
[required]
[datatype(datatype.emailaddress)]
[display(name = "email address")]
public string email { get; set; }
[required]
[stringlength(100, errormessage = "the {0} must be at least {2} characters long.", minimumlength = 6)]
[datatype(datatype.password)]
[display(name = "password")]
public string password { get; set; }
[datatype(datatype.password)]
[display(name = "confirm password")]
[compare("password", errormessage = "the password and confirmation password do not match.")]
public string confirmpassword { get; set; }
}
{
[required]
[display(name = "user name")]
public string username { get; set; }
[required]
[datatype(datatype.emailaddress)]
[display(name = "email address")]
public string email { get; set; }
[required]
[stringlength(100, errormessage = "the {0} must be at least {2} characters long.", minimumlength = 6)]
[datatype(datatype.password)]
[display(name = "password")]
public string password { get; set; }
[datatype(datatype.password)]
[display(name = "confirm password")]
[compare("password", errormessage = "the password and confirmation password do not match.")]
public string confirmpassword { get; set; }
}
相关文章
- ASP.NET 教程
- ASP.NET Web Pages HTML 表单
- ASP.NET Web Pages 对象
- ASP.NET Web Pages 文件
- ASP.NET Web Pages WebGrid
- ASP.NET Web Pages 图表
- ASP.NET Web 的 C# 和 VB 实例
- ASP.NET WebPages 帮助器参考手册
- ASP.NET Razor C# 循环和数组
- ASP.NET Razor VB 变量
- ASP.NET MVC 简介
- ASP.NET MVC 模型
- ASP.NET 服务器控件
- ASP.NET ViewState
- ASP.NET TextBox 控件
- ASP.NET Button 控件
- ASP.NET 数据绑定
- ASP.NET SortedList
- ASP.NET 母版页
- ASP.NET HTML 服务器控件