change middleware

release
Amir Hossein Khademi 2024-03-09 11:38:16 +03:30
parent ca3959c60c
commit f18c415979
2 changed files with 7 additions and 2 deletions

View File

@ -101,6 +101,10 @@ if (app.Environment.IsDevelopment())
//app.UseSwagger(); //app.UseSwagger();
//app.UseSwaggerUI(); //app.UseSwaggerUI();
} }
else
{
app.UseHsts();
}
app.UseCors(x => x app.UseCors(x => x
.SetIsOriginAllowed(origin => true) .SetIsOriginAllowed(origin => true)
.AllowAnyMethod() .AllowAnyMethod()

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Security.Cryptography; using System.Security.Cryptography;
using Microsoft.AspNetCore.Http;
using NetinaShop.Repository.Migrations; using NetinaShop.Repository.Migrations;
using Refit; using Refit;
@ -146,7 +147,7 @@ public class ExceptionHandlerMiddleware
context.Response.StatusCode = (int)httpStatusCode; context.Response.StatusCode = (int)httpStatusCode;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsync(json); await context.Response.WriteAsJsonAsync(result);
} }
@ -172,7 +173,7 @@ public class ExceptionHandlerMiddleware
context.Response.StatusCode = (int)httpStatusCode; context.Response.StatusCode = (int)httpStatusCode;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsync(json); await context.Response.WriteAsJsonAsync(result);
} }
void SetUnAuthorizeResponse(Exception exception) void SetUnAuthorizeResponse(Exception exception)