Bot Framework对话框中的错误处理

编程入门 行业动态 更新时间:2024-10-26 16:30:56
本文介绍了Bot Framework对话框中的错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何捕获对话框中的所有异常?是否有类似ASP.NET异常过滤器的内容? 我想根据异常类型向用户发送不同的消息.

How can I catch all exceptions in dialogs? Is there something like ASP.NET Exception Filter? I want to send different messages to user depending on exception type.

谢谢

推荐答案

您可以使用ExceptionFilter这个事实是正确的.

You are right about the fact that you can use ExceptionFilter.

您只需要执行以下操作:

You just have to do the following:

创建您的ExceptionFilter 类,例如,以在Application Insights中强制跟踪异常(或在您的情况下处理特定的异常类型):

Create your ExceptionFilter class, for example to force the tracking of the exception in Application Insights (or in your case handle specific exception types):

using Microsoft.ApplicationInsights; using System.Net.Http; using System.Web.Http.Filters; namespace BotDemo.App_Start { public class ExceptionFilter : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext ctx) { HandleError(ctx); } private static void HandleError(HttpActionExecutedContext ctx) { ctx.Response = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError) { Content = new StringContent(ctx.Exception.Message) }; var client = new TelemetryClient(); client.TrackException(ctx.Exception); } } }

请不要忘记在Application_Start()中定义例外过滤器:

public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { GlobalConfiguration.Configuration.Filters.Add(new ExceptionFilter()); ...

就是这样.

实际上Bot Framework模板使用的是ASP.Net,因此您具有所有正常功能.

In fact Bot Framework template is using ASP.Net, so you have all the normal features.

更多推荐

Bot Framework对话框中的错误处理

本文发布于:2023-11-17 06:26:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   对话框中   Bot   Framework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!