From d01950589cc2db1ec3a8b2647f9d2c021c2da6bf Mon Sep 17 00:00:00 2001 From: Yaser Moradi Date: Thu, 16 Nov 2023 13:16:57 +0100 Subject: [PATCH] feat(templates):fix http response handling related issues #6066 (#6067) --- .../src/BlazorWeb.Client/BlazorWeb.Client.csproj | 7 +++++++ .../Pages/Categories/CategoriesPage.razor.cs | 3 ++- .../BlazorWeb.Client/Pages/Products/ProductsPage.razor.cs | 2 +- .../src/BlazorWeb.Server/Components/App.razor | 2 +- .../src/BlazorWeb.Server/Startup/Middlewares.cs | 4 ++-- .../src/Client/App/Boilerplate.Client.App.csproj | 2 +- .../Client/Core/Pages/Categories/CategoriesPage.razor.cs | 3 ++- .../src/Client/Core/Pages/Products/ProductsPage.razor.cs | 3 ++- .../src/Client/Web/Boilerplate.Client.Web.csproj | 2 +- .../Bit.Websites.Careers.Server/Components/App.razor.cs | 2 +- .../src/Bit.Websites.Careers.Server/Startup/Middlewares.cs | 4 ++-- .../Bit.Websites.Platform.Server/Components/App.razor.cs | 2 +- .../Bit.Websites.Platform.Server/Startup/Middlewares.cs | 4 ++-- .../src/Bit.Websites.Sales.Server/Components/App.razor.cs | 2 +- .../src/Bit.Websites.Sales.Server/Startup/Middlewares.cs | 4 ++-- 15 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/BlazorWeb.Client.csproj b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/BlazorWeb.Client.csproj index 2c5d8970f5..116e8b326f 100644 --- a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/BlazorWeb.Client.csproj +++ b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/BlazorWeb.Client.csproj @@ -62,6 +62,13 @@ + + + + + + + diff --git a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Categories/CategoriesPage.razor.cs b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Categories/CategoriesPage.razor.cs index 031de1b5cd..b01f116b35 100644 --- a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Categories/CategoriesPage.razor.cs +++ b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Categories/CategoriesPage.razor.cs @@ -62,8 +62,9 @@ private void PrepareGridDataProvider() return BitDataGridItemsProviderResult.From(data.Items!, (int)data.TotalCount); } - catch + catch (Exception exp) { + ExceptionHandler.Handle(exp); return BitDataGridItemsProviderResult.From(new List { }, 0); } finally diff --git a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Products/ProductsPage.razor.cs b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Products/ProductsPage.razor.cs index 7c2cfb078f..6b80cbc749 100644 --- a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Products/ProductsPage.razor.cs +++ b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Client/Pages/Products/ProductsPage.razor.cs @@ -63,7 +63,7 @@ private void PrepareGridDataProvider() return BitDataGridItemsProviderResult.From(data!.Items!, (int)data!.TotalCount); } - catch + catch (Exception exp) { return BitDataGridItemsProviderResult.From(new List { }, 0); } diff --git a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Components/App.razor b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Components/App.razor index 650f871437..3c195cf95c 100644 --- a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Components/App.razor +++ b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Components/App.razor @@ -31,8 +31,8 @@ @if (HttpContext.Request.IsCrawlerClient() is false) { - + @*#if (sample == "AdminPanel")*@ @*#endif*@ diff --git a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Startup/Middlewares.cs b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Startup/Middlewares.cs index f34fd38fe6..74370887ee 100644 --- a/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Startup/Middlewares.cs +++ b/src/Templates/BlazorWeb/Bit.BlazorWeb/src/BlazorWeb.Server/Startup/Middlewares.cs @@ -32,11 +32,11 @@ public static void Use(WebApplication app, IHostEnvironment env, IConfiguration if (httpContext.Response.StatusCode is 404) { - httpContext.Response.Redirect($"not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); } else if (httpContext.Response.StatusCode is 401) { - httpContext.Response.Redirect($"not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); } } }); diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/App/Boilerplate.Client.App.csproj b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/App/Boilerplate.Client.App.csproj index ccb55a256f..9bbfa0e3ef 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/App/Boilerplate.Client.App.csproj +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/App/Boilerplate.Client.App.csproj @@ -41,7 +41,7 @@ true True - all + all diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Categories/CategoriesPage.razor.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Categories/CategoriesPage.razor.cs index 29a474d22b..ba8a9b678e 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Categories/CategoriesPage.razor.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Categories/CategoriesPage.razor.cs @@ -62,8 +62,9 @@ private void PrepareGridDataProvider() return BitDataGridItemsProviderResult.From(data.Items!, (int)data.TotalCount); } - catch + catch (Exception exp) { + ExceptionHandler.Handle(exp); return BitDataGridItemsProviderResult.From(new List { }, 0); } finally diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Products/ProductsPage.razor.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Products/ProductsPage.razor.cs index 1d5b305d4b..bf02046678 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Products/ProductsPage.razor.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Core/Pages/Products/ProductsPage.razor.cs @@ -63,8 +63,9 @@ private void PrepareGridDataProvider() return BitDataGridItemsProviderResult.From(data!.Items!, (int)data!.TotalCount); } - catch + catch (Exception exp) { + ExceptionHandler.Handle(exp); return BitDataGridItemsProviderResult.From(new List { }, 0); } finally diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Web/Boilerplate.Client.Web.csproj b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Web/Boilerplate.Client.Web.csproj index 8a3ba3bb66..d76b6d059c 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Web/Boilerplate.Client.Web.csproj +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Web/Boilerplate.Client.Web.csproj @@ -65,7 +65,7 @@ - + diff --git a/src/Websites/Careers/src/Bit.Websites.Careers.Server/Components/App.razor.cs b/src/Websites/Careers/src/Bit.Websites.Careers.Server/Components/App.razor.cs index 190da58877..19f6e5a4bd 100644 --- a/src/Websites/Careers/src/Bit.Websites.Careers.Server/Components/App.razor.cs +++ b/src/Websites/Careers/src/Bit.Websites.Careers.Server/Components/App.razor.cs @@ -13,7 +13,7 @@ protected override void OnInitialized() { HttpContext.Response.GetTypedHeaders().CacheControl = new() { - MaxAge = TimeSpan.FromDays(7), + MaxAge = TimeSpan.FromDays(1), Public = true }; }, null!); diff --git a/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs b/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs index 534a2c0549..5247560b11 100644 --- a/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs +++ b/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs @@ -31,11 +31,11 @@ public static void Use(WebApplication app, IHostEnvironment env, IConfiguration if (httpContext.Response.StatusCode is 404) { - httpContext.Response.Redirect($"not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); } else if (httpContext.Response.StatusCode is 401) { - httpContext.Response.Redirect($"not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); } } }); diff --git a/src/Websites/Platform/src/Bit.Websites.Platform.Server/Components/App.razor.cs b/src/Websites/Platform/src/Bit.Websites.Platform.Server/Components/App.razor.cs index 88728dabb4..f968663c5a 100644 --- a/src/Websites/Platform/src/Bit.Websites.Platform.Server/Components/App.razor.cs +++ b/src/Websites/Platform/src/Bit.Websites.Platform.Server/Components/App.razor.cs @@ -13,7 +13,7 @@ protected override void OnInitialized() { HttpContext.Response.GetTypedHeaders().CacheControl = new() { - MaxAge = TimeSpan.FromDays(7), + MaxAge = TimeSpan.FromDays(1), Public = true }; }, null!); diff --git a/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs b/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs index 345b1733c4..3c142af918 100644 --- a/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs +++ b/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs @@ -31,11 +31,11 @@ public static void Use(WebApplication app, IHostEnvironment env, IConfiguration if (httpContext.Response.StatusCode is 404) { - httpContext.Response.Redirect($"not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); } else if (httpContext.Response.StatusCode is 401) { - httpContext.Response.Redirect($"not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); } } }); diff --git a/src/Websites/Sales/src/Bit.Websites.Sales.Server/Components/App.razor.cs b/src/Websites/Sales/src/Bit.Websites.Sales.Server/Components/App.razor.cs index b5cad7956b..c98a7f9596 100644 --- a/src/Websites/Sales/src/Bit.Websites.Sales.Server/Components/App.razor.cs +++ b/src/Websites/Sales/src/Bit.Websites.Sales.Server/Components/App.razor.cs @@ -13,7 +13,7 @@ protected override void OnInitialized() { HttpContext.Response.GetTypedHeaders().CacheControl = new() { - MaxAge = TimeSpan.FromDays(7), + MaxAge = TimeSpan.FromDays(1), Public = true }; }, null!); diff --git a/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs b/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs index b3ffa1f6ca..e1716398d0 100644 --- a/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs +++ b/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs @@ -31,11 +31,11 @@ public static void Use(WebApplication app, IHostEnvironment env, IConfiguration if (httpContext.Response.StatusCode is 404) { - httpContext.Response.Redirect($"not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-found?url={httpContext.Request.GetEncodedPathAndQuery()}"); } else if (httpContext.Response.StatusCode is 401) { - httpContext.Response.Redirect($"not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); + httpContext.Response.Redirect($"/not-authorized?redirectUrl={httpContext.Request.GetEncodedPathAndQuery()}"); } } });