Skip to content

Commit

Permalink
AccessDenied 拒絕訪問功能
Browse files Browse the repository at this point in the history
  • Loading branch information
malagege committed Aug 23, 2022
1 parent 2a21605 commit 066d9d2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions AuthSample/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public AccountController(UserManager<ApplicationUser> userManager, SignInManager
_signInManger = signInManager;
}

public IActionResult AccessDenied()
{
return View();
}


[HttpGet]
public IActionResult Register()
{
Expand Down
6 changes: 6 additions & 0 deletions AuthSample/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,11 @@ public async Task<IActionResult> EditUserInRoleAsync(IList<UserRoleViewModel> mo
}

#endregion

[Authorize(Roles = "admin")]
public string TestCheckAdminRole()
{
return "Hello, Admin";
}
}
}
7 changes: 7 additions & 0 deletions AuthSample/Views/Account/AccessDenied.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@{
}


<div>
<h1>無權限訪問</h1>
</div>

0 comments on commit 066d9d2

Please sign in to comment.