日期:2014-05-17 浏览次数:20480 次
public class UserAuthorize : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (!httpContext.Request.IsAuthenticated) //首要条件:必须登录,必须有身份验证票。
return false;
string controller = httpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
string action = httpContext.Request.RequestContext.RouteData.Values["action"].ToString();
using (var db = new WEBVODEntities())
{
List<CtrlActRole> tempList = db.CtrlActRole.Where(a => a.ControllerName == controller && a.ActionName == action).ToList();
if (tempList.Count == 0) //如果没有找到记录,表示不需要权限控制
return true;
foreach (var ctrlActRole in tempList)
{
string roleField = ctrlActRole.RoleField; //获取对应的数据库字段