forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequireAdminAttribute.cs
More file actions
25 lines (23 loc) · 848 Bytes
/
Copy pathRequireAdminAttribute.cs
File metadata and controls
25 lines (23 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using System.Net.Http;
using System.Security.Principal;
using System.Threading;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace System.Web.Http
{
public class RequireAdminAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext context)
{
// do authorization based on the principle.
IPrincipal principal = Thread.CurrentPrincipal;
if (principal == null || !principal.IsInRole("Administrators"))
{
context.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
}
}
}