QiFeng.ZWY.MagWeb/Filter/AuthorizationAttribute.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
namespace QiFeng.LMSD.MagWeb
{
/// <summary>
/// 用户登录验证
/// <para>如果不需要处理用户登录,则请指定AllowAnonymousAttribute属性</para>
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class AuthorizationAttribute : FilterAttribute, IAuthorizationFilter
{
/// <summary>
/// 处理用户登录
/// </summary>
public void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext.HttpContext == null)
{
throw new Exception("此特性只适合于Web应用程序使用!");
}
string authSaveType = ConfigurationManager.AppSettings["AuthSaveType"] ?? "Cookie";
string userUrl = ConfigurationManager.AppSettings["AuthUserUrl"];
switch (authSaveType.ToUpper())
{
case "SESSION":
if (filterContext.HttpContext.Session == null)
{
throw new Exception("服务器Session不可用!");
}
if (!filterContext.ActionDescriptor.IsDefined(typeof (AllowAnonymousAttribute), true)
&&
!filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(
typeof (AllowAnonymousAttribute), true))
{
if (filterContext.HttpContext.Session["McAccounts"] == null)
{
string url = string.Empty;
try
{
url = HttpContext.Current.Request.Url.ToString();
}
catch
{
}
filterContext.Result = new RedirectResult(userUrl + "?returnurl=" + url);
}
}
break;
case "COOKIE":
if (!filterContext.ActionDescriptor.IsDefined(typeof (AllowAnonymousAttribute), true)
&&
!filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(
typeof (AllowAnonymousAttribute), true))
{
if (filterContext.HttpContext.Request.Cookies["McAccounts"] == null)
{
string url = string.Empty;
后面还有 17 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。