Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use razor page to return error pages. #20687

Merged
merged 1 commit into from
Oct 8, 2024
Merged

Conversation

maliming
Copy link
Member

@maliming maliming commented Sep 1, 2024

You can use abp generate-razor-page to generate a page class and then use it in the ASPNET Core pipeline to return an HTML page.

Razor page:

@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>

Generate code by abp generate-razor-page:

internal class AbpMvcLibsErrorPage : AbpCompilationRazorPageBase
{
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
#nullable restore
#line 3 "AbpMvcLibsErrorPage.cshtml"
Response.ContentType = "text/html; charset=utf-8";
Response.StatusCode = 500;
#line default
#line hidden
#nullable disable
WriteLiteral(@"
<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>
");
}
#pragma warning restore 1998
}
}

Usage:

var errorPage = new AbpMvcLibsErrorPage();
await errorPage.ExecuteAsync(httpContext);
return;

@maliming maliming added this to the 9.0-preview milestone Sep 1, 2024
@maliming maliming changed the title Use razor paeg to return error pages. Use razor page to return error pages. Sep 1, 2024
@hikalkan hikalkan merged commit f3fd4ce into dev Oct 8, 2024
3 checks passed
@hikalkan hikalkan deleted the AbpCompilationRazorPageBase branch October 8, 2024 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants