Skip to content

Commit

Permalink
Merge pull request #20687 from abpframework/AbpCompilationRazorPageBase
Browse files Browse the repository at this point in the history
Use razor page to return error pages.
  • Loading branch information
hikalkan authored Oct 8, 2024
2 parents 733bd07 + 739fa4c commit f3fd4ce
Show file tree
Hide file tree
Showing 15 changed files with 793 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" />
</ItemGroup>

<ItemGroup>
<Content Remove="Volo\Abp\AspNetCore\MultiTenancy\Views\MultiTenancyMiddlewareErrorPage.cshtml" />
<None Include="Volo\Abp\AspNetCore\MultiTenancy\Views\MultiTenancyMiddlewareErrorPage.cshtml" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Volo.Abp.AspNetCore.MultiTenancy.Views;
using Volo.Abp.AspNetCore.RazorViews;
using Volo.Abp.Http;
using Volo.Abp.Json;
using Volo.Abp.MultiTenancy;
Expand Down Expand Up @@ -68,7 +70,7 @@ public AbpAspNetCoreMultiTenancyOptions()
}
}
context.Response.Headers.Add("Abp-Tenant-Resolve-Error", HtmlEncoder.Default.Encode(exception.Message));
context.Response.Headers.Append("Abp-Tenant-Resolve-Error", HtmlEncoder.Default.Encode(exception.Message));
if (isCookieAuthentication && context.Request.Method.Equals("Get", StringComparison.OrdinalIgnoreCase) && !context.Request.IsAjax())
{
context.Response.Redirect(context.Request.GetEncodedUrl());
Expand Down Expand Up @@ -133,18 +135,11 @@ public AbpAspNetCoreMultiTenancyOptions()
}
else
{
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
context.Response.ContentType = "text/html";
var message = exception.Message;
var details = exception is BusinessException businessException ? businessException.Details : string.Empty;
await context.Response.WriteAsync($"<html lang=\"{HtmlEncoder.Default.Encode(CultureInfo.CurrentCulture.Name)}\"><body>\r\n");
await context.Response.WriteAsync($"<h3>{HtmlEncoder.Default.Encode(message)}</h3>{HtmlEncoder.Default.Encode(details!)}<br>\r\n");
await context.Response.WriteAsync("</body></html>\r\n");
// Note the 500 spaces are to work around an IE 'feature'
await context.Response.WriteAsync(new string(' ', 500));
var errorPage = new MultiTenancyMiddlewareErrorPage(new MultiTenancyMiddlewareErrorPageModel(message, details!));
await errorPage.ExecuteAsync(context);
}
return true;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@using System.Globalization
@using Volo.Abp.AspNetCore.MultiTenancy.Views
@using Volo.Abp.AspNetCore.RazorViews
@inherits AbpCompilationRazorPageBase
@{
Response.ContentType = "text/html; charset=utf-8";
Response.StatusCode = 404;
}

@functions{
public MultiTenancyMiddlewareErrorPage(MultiTenancyMiddlewareErrorPageModel model)
{
Model = model;
}

public MultiTenancyMiddlewareErrorPageModel Model { get; set; }
}

<html lang="@HtmlEncoder.Encode(CultureInfo.CurrentCulture.Name)">
<head>
<meta charset="utf-8" />
<title>@HtmlEncoder.Encode(Model.Message)</title>
</head>
<body>
<h3>@HtmlEncoder.Encode(Model.Message)</h3>
<p>@HtmlEncoder.Encode(Model.Details)<p/>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Volo.Abp.AspNetCore.MultiTenancy.Views;

public class MultiTenancyMiddlewareErrorPageModel
{
public string Message { get; set; }

public string Details { get; set; }

public MultiTenancyMiddlewareErrorPageModel(string message, string details)
{
Message = message;
Details = details;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" />
</ItemGroup>

<ItemGroup>
<Content Remove="Volo\Abp\AspNetCore\Mvc\Libs\AbpMvcLibsErrorPage.cshtml" />
<None Include="Volo\Abp\AspNetCore\Mvc\Libs\AbpMvcLibsErrorPage.cshtml" />
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@using Volo.Abp.AspNetCore.RazorViews
@inherits AbpCompilationRazorPageBase
@{
Response.ContentType = "text/html; charset=utf-8";
Response.StatusCode = 500;
}

<html>
<head>
<meta charset="utf-8" />
<title>Error - The Libs folder is missing!</title>
</head>
<body>
<h1> &#9888;&#65039; The Libs folder under the <code style="background-color: #e7e7e7;">wwwroot/libs</code> directory is empty!</h1>

<p>The Libs folder contains mandatory NPM Packages for running the project.</p>

<p>Make sure you run the <code style="background-color: #e7e7e7;">abp install-libs</code> CLI tool command.</p>

<p>For more information, check out the <a href="https://abp.io/docs/latest/CLI#install-libs">ABP CLI documentation</a></p>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.FileProviders;
using Volo.Abp.AspNetCore.RazorViews;
using Volo.Abp.DependencyInjection;

namespace Volo.Abp.AspNetCore.Mvc.Libs;
Expand All @@ -35,22 +36,8 @@ public virtual void CheckLibs(ApplicationInitializationContext context)
{
if (!await CheckLibsAsyncOnceAsync(httpContext))
{
httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
httpContext.Response.ContentType = "text/html";
await httpContext.Response.WriteAsync(
"<html>" +
" <head>" +
" <title>Error - The Libs folder is missing!</title>" +
" </head>" +
" <body>" +
" <h1> &#9888;&#65039; The Libs folder under the <code style='background-color: #e7e7e7;'>wwwroot/libs</code> directory is empty!</h1>" +
" <p>The Libs folder contains mandatory NPM Packages for running the project.</p>" +
" <p>Make sure you run the <code style='background-color: #e7e7e7;'>abp install-libs</code> CLI tool command.</p>" +
" <p>For more information, check out the <a href='https://abp.io/docs/latest/CLI#install-libs'>ABP CLI documentation</a></p>" +
" </body>" +
"</html>",
Encoding.UTF8
);
var errorPage = new AbpMvcLibsErrorPage();
await errorPage.ExecuteAsync(httpContext);
return;
}
Expand Down
Loading

0 comments on commit f3fd4ce

Please sign in to comment.