-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMiscTestControllers.cs
More file actions
56 lines (43 loc) · 1.6 KB
/
MiscTestControllers.cs
File metadata and controls
56 lines (43 loc) · 1.6 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
public class BaseController : Controller {
// GOOD
[Authorize]
public virtual ActionResult Edit1(int id) { return View(); }
}
class MyAuthorizeAttribute : AuthorizeAttribute { }
class MyAllowAnonymousAttribute : AllowAnonymousAttribute { }
public class AController : BaseController {
// GOOD - Authorize is inherited from overridden method
public override ActionResult Edit1(int id) { return View(); }
// GOOD - A subclass of Authorize is used
[MyAuthorize]
public ActionResult Edit2(int id) { return View(); }
}
[Authorize]
public class BaseAuthController : Controller {
// BAD - A subclass of AllowAnonymous is used
[MyAllowAnonymous]
public virtual ActionResult EditAnon(int id) { return View(); }
}
public class BController : BaseAuthController {
// GOOD - Authorize is inherited from parent class
public ActionResult Edit3(int id) { return View(); }
// BAD - MyAllowAnonymous is inherited from overridden method
public override ActionResult EditAnon(int id) { return View(); }
}
[AllowAnonymous]
public class BaseAnonController : Controller {
}
public class CController : BaseAnonController {
// BAD - AllowAnonymous is inherited from base class and overrides Authorize
[Authorize]
public ActionResult Edit4(int id) { return View(); }
}
[Authorize]
public class BaseGenController<T> : Controller {
}
public class SubGenController : BaseGenController<string> {
// GOOD - Authorize is inherited from parent class
public ActionResult Edit5(int id) { return View(); }
}