如何捕获对话框中的所有异常?是否有类似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对话框中的错误处理
发布评论