在网上找到mvc一段代码但是看不懂,不知道怎么用,哪位大神能帮我注释一下
publicclassCustAuthorizeAttribute:AuthorizeAttribute{privatestring[]roles;usingSystem...
public class CustAuthorizeAttribute : AuthorizeAttribute
{
private string[] roles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PermissionWEB
{
public CustAuthorizeAttribute(params String[] role)
{
roles = role;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
String role = httpContext.Request.QueryString["role"];
if (role != null)
{
return roles.Contains(role);
}
return base.AuthorizeCore(httpContext);
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
UrlHelper url = new UrlHelper(filterContext.RequestContext);
filterContext.Result = new RedirectResult("~/Home/Login");
}
} 展开
{
private string[] roles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PermissionWEB
{
public CustAuthorizeAttribute(params String[] role)
{
roles = role;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
String role = httpContext.Request.QueryString["role"];
if (role != null)
{
return roles.Contains(role);
}
return base.AuthorizeCore(httpContext);
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
UrlHelper url = new UrlHelper(filterContext.RequestContext);
filterContext.Result = new RedirectResult("~/Home/Login");
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询