ASP.NET MVC使用AuthorizeAttribute做身份验证操作 [ASP_NET_MVC]
using System;
using System.Web;
using System.Web.Mvc;
using Whir.Framework.Helper;

namespace Whir.Foundation.Attribute.Authorize
{
    /// <summary>
    ///     后台管理身份认证
    /// </summary>
    public class AdminAuthorizeAttribute : AuthorizeAttribute
    {
        /// <summary>
        ///     身份验证判断逻辑
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            return WhirContext.Current.Admin.Identity.IsAuthenticated;
        }

        /// <summary>
        ///     验证失败时触发
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            string loginUrl = PathHelper.BasePath + "Admin/Login";
            filterContext.HttpContext.Response.Redirect(loginUrl, true);
        }
    }
}