Guest User

Untitled

a guest
Nov 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6.  
  7. namespace MvcFilters.Infrastructure
  8. {
  9.     public class CustomAuthAttribute : AuthorizeAttribute
  10.     {
  11.         private string[] allowedUsers;
  12.  
  13.         public CustomAuthAttribute(params string[] users)
  14.         {
  15.             allowedUsers = users;
  16.         }
  17.  
  18.         protected override bool AuthorizeCore(HttpContextBase httpContext)
  19.         {
  20.             return httpContext.Request.IsAuthenticated &&
  21.                     allowedUsers.Contains(httpContext.User.Identity.Name, StringComparer.InvariantCultureIgnoreCase);
  22.         }
  23.     }
  24. }
Add Comment
Please, Sign In to add comment