public ActionResult Index(){...}
[Authorize(Roles = "admins")]
[Authorize(Roles = "admins")]
public ActionResult Index()
{
...
}
<authentication mode="Forms"> <forms loginUrl="~/Login" timeout="2880" /> </authentication>
public class LogOnModel
{
[Required]
[Display(Name = "用户名")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "密码")]
public string Password { get; set; }
[Display(Name = "下次自动登陆")]
public bool RememberMe { get; set; }
}
@model Weibo.Models.LogOnModel //LogOnModel 是CDBTemplate.cs文件里的一个类
@using (Html.BeginForm("Login","Login",FormMethod.Post)) {
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName, "请输入用户名!", new {style="color: #f00" })
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password,"请输入密码!",new {style="color: #f00" })
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
@Html.ActionLink("忘记密码", "forgotpwd", null, new {@class="rt",target="_blank" })
<input type="submit" value="登陆微博" />
}
[HttpPost, ActionName("Login")]
public void Login(FormCollection collection)
{
object obj = SqlHelper.ExecuteScalar("select UserId from CDBUsers where UserName=@uname and Password=@pwd",
new SqlParameter("@uname", collection[0]),
new SqlParameter("@pwd", Weibo.Models.Myencrypt.myencrypt(collection[1])));
if (obj != null)
{
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
collection[0],
DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
"admins"
);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
System.Web.HttpCookie authCookie = new System.Web.HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
}
Response.Redirect("~/");
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有