我试图返回一个视图,不会根据我的应用程序可能发生的某些错误向用户发出重定向,我想处理错误+在基本控制器中记录它们,我不希望错误传播到我的Global.asax - Application_Error()方法因为我希望这个方法能够处理我的应用程序中的任何其他错误,例如用户输入虚假URL,有没有人找到解决方法?
注意:我已经离开了我的注释代码,因为我有一些问题的解决方法,这也表明我有可能处理的多个例外...
编辑:如果我在这个OnException覆盖中发出RedirectToAction覆盖一切按预期工作,但我只想返回视图,没有重定向...
我的基本控制器方法是:
protected override void OnException(ExceptionContext filterContext)
{
//dont interfere if the exception is already handled
if (filterContext.ExceptionHandled)
return;
//let the next request know what went wrong
filterContext.Controller.TempData["exception"] = filterContext.Exception;
//log exception
_logging.Error(User.Identity.Name, ExceptionHelper.BuildWebExceptionMessage(filterContext.Exception));
//set up redirect to my global error handler
//if (filterContext.Exception.GetType() == typeof(NoAccessException))
// filterContext.Result = View(new RouteValueDictionary
// (new { area = "", controller = "Error", action = "PublicError" }));
//else {
//Only return view, no need for redirection
filterContext.Result = View(new …Run Code Online (Sandbox Code Playgroud) 我的设置是带有开发容器的 VS Code。当我启动一个生成类似于 URL 的输出的应用程序时,VS Code 将提取端口号并自动转发该端口。此处详细描述了此过程。
我的问题有两个:
自动转发端口有什么好处?
如何有效防止 VS Code 自动转发任意端口?
我考虑和测试的解决方案包括使用以下设置:
{
// Prevent VS Code's automatic port forwarding
"remote.autoForwardPorts": false,
"remote.restoreForwardedPorts": false,
"remote.portsAttributes": {
"1-65000": {
"label": "Application",
"onAutoForward": "ignore"
}
},
}
Run Code Online (Sandbox Code Playgroud)
我已经在用户级别、开发容器级别(也称为远程)和工作区级别尝试了这些设置。此外,我也尝试过这些设置devcontainer.json。我还重建了开发容器以确保应用设置。
然而,我在这方面运气并不好。VS Code 会自动转发端口。我正在寻找持久的解决方案。
c# ×1