Skip to content

Commit b190594

Browse files
committed
Add error 403 page
1 parent 16afbe7 commit b190594

File tree

8 files changed

+67
-1
lines changed

8 files changed

+67
-1
lines changed

aspnet-core/src/AbpCompanyName.AbpProjectName.Core/Localization/SourceFiles/AbpProjectName-tr.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,8 @@
117117
<text name="ResetPasswordStepOneInfo">1. Yönetici şifresini girin</text>
118118
<text name="ResetPasswordStepTwoInfo">2. Bu şifreyi kaydettikten sonra ilgili kullanıcıya gönderin</text>
119119
<text name="UsersActivation">Kullanıcıları aktifleştirme</text>
120+
<text name="403PageHeader">Yetkisiz Erişim</text>
121+
<text name="403PageDescription">Bu sayfaya erişmek için yetkiniz yok. Lütfen yöneticinizle iletişime geçin.</text>
122+
<text name="403PageButton">Dashboard'a dön</text>
120123
</texts>
121124
</localizationDictionary>

aspnet-core/src/AbpCompanyName.AbpProjectName.Core/Localization/SourceFiles/AbpProjectName.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,8 @@
117117
<text name="ResetPasswordStepOneInfo">1. Enter your administrator password</text>
118118
<text name="ResetPasswordStepTwoInfo">2. Copy this random password so you can send it to the user</text>
119119
<text name="UsersActivation">Users activation</text>
120+
<text name="403PageHeader">Forbidden</text>
121+
<text name="403PageDescription">You don't have permission to access this resource. Please contact your administrator.</text>
122+
<text name="403PageButton">Go back to Dashboard</text>
120123
</texts>
121124
</localizationDictionary>

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Controllers/AccountController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,16 @@ protected virtual async Task<List<Tenant>> FindPossibleTenantsOfUserAsync(UserLo
367367

368368
#endregion
369369

370+
#region 403 Forbidden
371+
372+
[Route("/Account/Forbidden")]
373+
public ActionResult Error403()
374+
{
375+
return View();
376+
}
377+
378+
#endregion
379+
370380
#region Helpers
371381

372382
public ActionResult RedirectToAppHome()

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Startup/AuthConfigurer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Text;
3+
using Abp.AspNetCore.Mvc.Authorization;
4+
using Microsoft.AspNetCore.Mvc;
35
using Microsoft.Extensions.Configuration;
46
using Microsoft.Extensions.DependencyInjection;
57
using Microsoft.IdentityModel.Tokens;
@@ -10,6 +12,11 @@ public static class AuthConfigurer
1012
{
1113
public static void Configure(IServiceCollection services, IConfiguration configuration)
1214
{
15+
services.ConfigureApplicationCookie(options =>
16+
{
17+
options.AccessDeniedPath = "/Account/Forbidden";
18+
});
19+
1320
if (bool.Parse(configuration["Authentication:JwtBearer:IsEnabled"]))
1421
{
1522
services.AddAuthentication()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@{
2+
ViewBag.Title = L("403PageHeader");
3+
ViewBag.HideTenantChange = true;
4+
}
5+
6+
@section styles
7+
{
8+
<link href="~/view-resources/Views/Account/Error403.css" rel="stylesheet" asp-append-version="true" />
9+
}
10+
11+
<div class="forbidden-box d-flex flex-column align-items-center justify-content-center text-center">
12+
<div class="d-flex align-items-center">
13+
<div class="display-1 text-warning me-3">
14+
403
15+
</div>
16+
</div>
17+
<h2 class="text-warning">
18+
<i class="fas fa-exclamation-triangle"></i> @L("403PageHeader")
19+
</h2>
20+
<div class="mt-4">
21+
<p class="lead text-muted">
22+
@L("403PageDescription")
23+
</p>
24+
<a href="@Url.Action("Index", "Home")" class="btn btn-primary">@L("403PageButton")</a>
25+
</div>
26+
</div>

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Views/Account/_Layout.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
var pageTitle = !string.IsNullOrWhiteSpace(ViewBag.Title) ? ViewBag.Title + " / " : "";
1414
pageTitle += "AbpProjectName";
15+
16+
var hideTenantChange = ViewBag.HideTenantChange != null && ViewBag.HideTenantChange == true;
17+
var showTenantChange = MultiTenancyConfig.IsEnabled && !hideTenantChange;
1518
}
1619
<!DOCTYPE html>
1720
<html lang="@LanguageManager.CurrentLanguage.Name">
@@ -31,7 +34,7 @@
3134
<a href="/"><b>AbpProjectName</b></a>
3235
</div>
3336
<div class="card">
34-
@if (MultiTenancyConfig.IsEnabled)
37+
@if (showTenantChange)
3538
{
3639
<div class="card-header">
3740
<vc:tenant-change></vc:tenant-change>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.login-box {
2+
width: inherit;
3+
}
4+
5+
.forbidden-box {
6+
max-width: 350px;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.login-box {
2+
width: inherit;
3+
}
4+
5+
.forbidden-box {
6+
max-width: 350px;
7+
}

0 commit comments

Comments
 (0)