src/Library/NetPro.Web.Api/Extensions/ApplicationBuilderExtensions.cs
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.NetPro;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace NetPro.Web.Api
{
/// <summary>
///IApplicationBuilder扩展
/// </summary>
public static class ApplicationBuilderExtensions
{
/// <summary>
/// Add exception handling
/// </summary>
/// <param name="application">Builder for configuring an application's request pipeline</param>
public static void UseNetProExceptionHandler(this IApplicationBuilder application)
{
var netConfig = application.ApplicationServices.GetService<NetProOption>();
var hostingEnvironment = application.ApplicationServices.GetService<IWebHostEnvironment>();
var logger = application.ApplicationServices.GetRequiredService<Microsoft.Extensions.Logging.ILogger<dynamic>>();
if (hostingEnvironment.IsDevelopment())
{
//get detailed exceptions for developing and testing purposes
application.UseDeveloperExceptionPage();
}
else
{
{
var webHelper = application.ApplicationServices.GetService<IWebHelper>();
//The global default handles exceptions
application.UseExceptionHandler(handler =>
{
handler.Run(async context =>
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.ContentType = "text/plain; charset=utf-8";
var contextFeature = context.Features.Get<IExceptionHandlerFeature>();
if (contextFeature != null)
{
//var exceptionHandlerPathFeature =
//context.Features.Get<IExceptionHandlerPathFeature>();
if (contextFeature.Error != null)
{
//Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException
var exError = contextFeature.Error;
后面还有 106 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。