From 54be1b95d7b73de8296559210217def795198350 Mon Sep 17 00:00:00 2001 From: andrenormanlang Date: Wed, 11 Sep 2024 08:48:40 +0200 Subject: [PATCH] enabling CORs for client site --- InventoryManagementSystem/Controllers/ProductController.cs | 5 +++++ InventoryManagementSystem/Program.cs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/InventoryManagementSystem/Controllers/ProductController.cs b/InventoryManagementSystem/Controllers/ProductController.cs index 3701be4..25394aa 100644 --- a/InventoryManagementSystem/Controllers/ProductController.cs +++ b/InventoryManagementSystem/Controllers/ProductController.cs @@ -114,6 +114,11 @@ public async Task>> PostProductsInBulk(IEnumer var category = await _context.Categories.FindAsync(productDto.CategoryId); var supplier = await _context.Suppliers.FindAsync(productDto.SupplierId); + if (productDto.Description.Length > 10000) + { + return BadRequest("Description cannot exceed 10,000 characters."); + } + if (category == null) { return BadRequest(new { message = $"Invalid Category ID: {productDto.CategoryId} for product: {productDto.Name}. Category does not exist." }); diff --git a/InventoryManagementSystem/Program.cs b/InventoryManagementSystem/Program.cs index 468cf7e..1653216 100644 --- a/InventoryManagementSystem/Program.cs +++ b/InventoryManagementSystem/Program.cs @@ -42,7 +42,7 @@ options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles; }); -// Enable CORS +// Enable CORS to allow requests from Blazor client builder.Services.AddCors(options => { options.AddPolicy("AllowBlazorClient", policy => @@ -88,7 +88,7 @@ app.UseHttpsRedirection(); app.UseStaticFiles(); -// Enable CORS +// Enable CORS with the configured policy app.UseCors("AllowBlazorClient"); app.UseRouting();