第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Asp.Net Core Razor Pages 異常處理中斷應(yīng)用程序

Asp.Net Core Razor Pages 異常處理中斷應(yīng)用程序

C#
慕田峪4524236 2023-04-29 15:47:53
我正在構(gòu)建一個(gè) Asp.Net Core 2.2 Razor Pages 應(yīng)用程序。我正在編寫(xiě)一個(gè)全局異常處理以避免在許多地方出現(xiàn) try catch 塊。我關(guān)注了文章 -異常處理參考這是演示解決方案鏈接這是我的代碼,在Startup.cs中if(env.IsDevelopment()){    //app.UseDeveloperExceptionPage(new DeveloperExceptionPageOptions {    //    SourceCodeLineCount = 2    //});    //app.UseDatabaseErrorPage();    app.UseExceptionHandler("/Error");    app.UseStatusCodePagesWithReExecute("/Error/{0}");    app.UseExceptionMiddleware();} else {...}在ExceptionMiddleware.cs中public ExceptionMiddleware(RequestDelegate next,IMailService emailSender){    _next = next;    _emailSender = emailSender;}public async Task InvokeAsync(HttpContext context){    try    {        await _next(context);    } catch(Exception ex)    {        EmailException(context,ex);    }}private async void EmailException(HttpContext context,Exception ex){    var uaString = context.Request.Headers["User-Agent"].ToString();    var ipAnonymizedString = context.Connection.RemoteIpAddress.AnonymizeIP();    var userId = "Unknown";    var profileId = "Unknown";    if(context.User.Identity.IsAuthenticated)    {        userId = context.User.FindFirstValue(ClaimTypes.NameIdentifier);        profileId = context.User.GetUserClaim(ClaimsKey.ProfileId);    }    var sb = new StringBuilder($"An error has occurred on {context.Request.Host}. \r\n \r\n");    sb.Append($"Path = {context.Request.Path} \r\n \r\n");    sb.Append($"Error Message = {ex.Message} \r\n");    sb.Append($"Error Source = {ex.Source} - {profileId} \r\n");    if(ex.InnerException != null)    {        sb.Append($"Inner Exception = {ex.InnerException.ToString()} \r\n");    } else    {        sb.Append("Inner Exception = null \r\n");    }    sb.Append($"Error StackTrace = {ex.StackTrace} \r\n");    await _emailSender.SendMasterEmailAsync($"Error on {context.Request.Host}.",sb.ToString(),uaString,ipAnonymizedString,userId);    throw ex;}
查看完整描述

目前暫無(wú)任何回答

  • 0 回答
  • 0 關(guān)注
  • 128 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)