File tree Expand file tree Collapse file tree 3 files changed +50
-4
lines changed
src/ProductConstructionService/ProductConstructionService.Api Expand file tree Collapse file tree 3 files changed +50
-4
lines changed Original file line number Diff line number Diff line change 1+ @page
2+ @model ProductConstructionService .Api .Pages .ErrorModel
3+ @using System .Net
4+ @using Microsoft .AspNetCore .Http
5+ @{
6+ ViewBag .Title = " Error" ;
7+ }
8+
9+ @if (Model .StatusCode == StatusCodes .Status401Unauthorized )
10+ {
11+ <div >
12+ Please <a href =" /Account/SignIn?returnUrl=@WebUtility.UrlEncode(Model.ReturnUrl)" >Sign In </a > to use this site . Make sure you have joined the
13+ <a href =" https://coreidentity.microsoft.com/manage/Entitlement/entitlement/dotnetesmaes-z54r" target =" _blank" >dotnetes - maestro - users group </a >.
14+ </div >
15+ }
16+ else
17+ {
18+ <div class =" alert alert-danger" >
19+ <strong >@Model.StatusCode </strong > @Model.ErrorMessage
20+ </div >
21+ }
Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+
4+ using Microsoft . AspNetCore . Diagnostics ;
5+ using Microsoft . AspNetCore . Mvc . RazorPages ;
6+
7+ namespace ProductConstructionService . Api . Pages ;
8+
9+ public class ErrorModel : PageModel
10+ {
11+ public new int StatusCode { get ; set ; }
12+
13+ public string ? ErrorMessage { get ; set ; }
14+
15+ public string ? ReturnUrl => HttpContext . Features . Get < IStatusCodeReExecuteFeature > ( ) ? . OriginalPath ;
16+
17+ public void OnGet ( int code )
18+ {
19+ StatusCode = code ;
20+ ErrorMessage = HttpContext . Items [ "ErrorMessage" ] ? . ToString ( ) ;
21+ if ( string . IsNullOrEmpty ( ErrorMessage ) )
22+ {
23+ ErrorMessage = "Unable to process request." ;
24+ }
25+ }
26+ }
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ await app.Services.UseLocalWorkItemQueues([
108108}
109109
110110// Add security headers
111+ app . UseStatusCodePagesWithReExecute ( "/Error" , "?code={0}" ) ;
111112app . ConfigureSecurityHeaders ( ) ;
112113
113114// Map pages and non-API controllers
@@ -120,9 +121,7 @@ await app.Services.UseLocalWorkItemQueues([
120121 controllers . AllowAnonymous ( ) ;
121122}
122123
123- // UseSpa fails on OPTIONS requests to index.html
124- // https://github.com/dotnet/aspnetcore/issues/5223#issuecomment-2445336133
125- app . MapWhen ( ctx => ctx . Request . Method != "OPTIONS" , a => a . UseSpa ( spa =>
124+ app . UseSpa ( spa =>
126125{
127126 if ( isDevelopment && Directory . Exists ( PcsStartup . LocalCompiledStaticFilesPath ) )
128127 {
@@ -135,7 +134,7 @@ await app.Services.UseLocalWorkItemQueues([
135134 {
136135 spa . Options . DefaultPageStaticFileOptions = new StaticFileOptions ( ) ;
137136 } ;
138- } ) ) ;
137+ } ) ;
139138
140139await app . SetWorkItemProcessorInitialState ( ) ;
141140
You can’t perform that action at this time.
0 commit comments