// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseHangfireDashboard(); // } // else { // app.UseHttpsRedirection(); // } // if (env.IsProduction()) { // app.UseExceptionHandler("/error"); // } app.UseStatusCodePages(async context => { if (context.HttpContext.Response.StatusCode == 401 && context.HttpContext.Response.ContentType != "application/json") { context.HttpContext.Response.ContentType = "application/json"; await context.HttpContext.Response.WriteAsync( JsonSerializer.Serialize(ResponseFormat.NotAuth().Value)); } else if (context.HttpContext.Response.StatusCode == 403 && context.HttpContext.Response.ContentType != "application/json") { context.HttpContext.Response.ContentType = "application/json"; await context.HttpContext.Response.WriteAsync( JsonSerializer.Serialize(ResponseFormat.PermissionDeniedMsg("شما به این قسمت دسترسی ندارید.") .Value)); } else if (context.HttpContext.Response.StatusCode == 400) { context.HttpContext.Response.ContentType = "application/json"; await context.HttpContext.Response.WriteAsync( JsonSerializer.Serialize(ResponseFormat.BadRequestMsg("درخواست نامعتبر").Value)); } else if (context.HttpContext.Response.StatusCode == 500) { context.HttpContext.Response.ContentType = "application/json"; await context.HttpContext.Response.WriteAsync( JsonSerializer.Serialize(ResponseFormat.InternalError("مشکلی در سرور رخ داده است.").Value)); } }); app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/V1 User/swagger.json", "V1 User"); options.SwaggerEndpoint("/swagger/V1 Admin/swagger.json", "V1 Admin"); }); app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() ); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseStaticFiles(); app.UseDirectoryBrowser(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }