62,046
社区成员
发帖
与我相关
我的任务
分享
public class OperatorAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
var formId = HttpContext.Current.User.Identity as FormsIdentity;
if (formId != null && formId.IsAuthenticated)
{
var rolesTemp = formId.Ticket.UserData.Split('&');
var roles = rolesTemp[0];
if (!Roles.Contains(roles))
{
filterContext.RequestContext.HttpContext.Response.Write("无权访问");
filterContext.RequestContext.HttpContext.Response.End();
}
else
{
FormsAuthentication.RedirectFromLoginPage(formId.Name,false);
}
}
else
{
FormsAuthentication.RedirectToLoginPage();
}
}
}
[OperatorAuthorize(Roles = "3,25,26,27,28,29")]
public ViewResult Index(int? currentPage)
{
int currentIndex = currentPage.HasValue ? currentPage.Value : 1;
int pageSize = CommonAction.GetPageSize();
int total = db.Clients.Count();
ViewBag.PageHTML = new WebDataPage().GetPageHTML(currentIndex, total, pageSize, CommonAction.GetAppIntByName("ShowNumber"));
int topIndex = (currentIndex - 1) * pageSize;
var query = db.Clients.OrderBy(em => em.ClientID).Skip(topIndex).Take(pageSize).ToList();
return View(query);
}