Diack
天高云淡,月冷风清,一片孤独的守候。希望有一片心灵的净土,忘却尘世的喧嚣,慢慢展现一种曾经向往的生活。

新建基类继承Controller,重写操作方法调用前事件,验证权限,调用时继承基类,  页面按钮组件权限,还是使用HttpHandler控制合适

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JiJin.Entity;

    public class BaseController : Controller
    {
        //保存免验证页面
        private Dictionary<string, string> UrlRoute = new Dictionary<string, string> { 
            { "Announcement", "Announcement" }
            };


        //重写方法调用前事件
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Session != null)
            {
                if (filterContext.HttpContext.Session["UserInfo"] != null)
                {
                    //验证用户登录
                       U_UserInfo UserInfo = Session["UserInfo"] as U_UserInfo;
                    if (UserInfo == null)
                    {
                     //没有登录跳转到登录页面
                        filterContext.Result = new RedirectResult("/Home/Login");
                    }

                    //判断是否进行过支付密码登录,没有则验证当前页面是否是免支付登录验证
                       if (!UserInfo.IsPayLogin)
                    {
              //获取当前访问的action
   string actionname = filterContext.RouteData.Values["Action"].ToString(); if (!UrlRoute.ContainsKey(actionname)) { //没有支付登录跳转支付登录页面 filterContext.Result = new RedirectResult("/Home/PawLogin"); } } } else { //没有登录跳转到登录页面 filterContext.Result = new RedirectResult("/Home/Login"); } } base.OnActionExecuting(filterContext); } }

 

 

posted on 2013-03-05 11:18  鱼遇雨愉  阅读(506)  评论(0编辑  收藏  举报