登录授权过滤器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Login.Mvc.Fatier
{
using System.Web.Mvc;
public class LoginFatier:AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
//filterContext.HttpContext.Session["URL"] = filterContext.HttpContext.Request.RawUrl;
if (filterContext.HttpContext.Session["UName"] == null)
{
filterContext.HttpContext.Response.Redirect("/Login/Login");
}
//base.OnAuthorization(filterContext);
}
}
}
登录时使用session获取用户名和Id
public int UserLogin(string Name,string Password)
{
var result = bll.UserLogin(Name, Password);
if (result > 0)
{
Session["UName"] = Name;
Session["ID"] = result;
}
return result;
}