ASP.NET MVC 安全
asp.net mvc - 安全
為了學(xué)習(xí) asp.net mvc,我們將構(gòu)建一個 internet 應(yīng)用程序。
第 8 部分:添加安全。
mvc 應(yīng)用程序安全
models 文件夾包含表示應(yīng)用程序模型的類。
visual web developer 自動創(chuàng)建 accountmodels.cs 文件,該文件包含用于應(yīng)用程序認證的模型。
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; }
}
相關(guān)文章
- 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# 循環(huán)和數(shù)組
- ASP.NET Razor VB 變量
- ASP.NET MVC 簡介
- ASP.NET MVC 模型
- ASP.NET 服務(wù)器控件
- ASP.NET ViewState
- ASP.NET TextBox 控件
- ASP.NET Button 控件
- ASP.NET 數(shù)據(jù)綁定
- ASP.NET SortedList
- ASP.NET 母版頁
- ASP.NET HTML 服務(wù)器控件