Skip to content

Commit c4178fe

Browse files
authored
[Rollout] Production rollout 2025-01-02 part 2 (#4292)
2 parents 6c14bbd + d5a6174 commit c4178fe

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

src/ProductConstructionService/ProductConstructionService.Api/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ await app.Services.UseLocalWorkItemQueues([
108108
}
109109

110110
// Add security headers
111+
app.UseStatusCodePagesWithReExecute("/Error", "?code={0}");
111112
app.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

140139
await app.SetWorkItemProcessorInitialState();
141140

0 commit comments

Comments
 (0)