我有一个方法,如:
public TResult DoSomethingWithLogging<TResult>(Func<TResult> someAction)
{
try
{
return someAction.Invoke();
}
catch (Exception ex)
{
LogException(ex)
throw;
}
Run Code Online (Sandbox Code Playgroud)
该方法使用如下:
var result = DoSomethingWithLogging(() => Foo());
Run Code Online (Sandbox Code Playgroud)
我还想记录内部捕获的异常Foo().我不能throw在catch里面使用Foo.
我怎么能抓住这样的例外?
例:
public static string Foo()
{
try
{
return "Foo";
}
catch (Exception)
{
// I have to log this exception too without adding anything to Foo
return "Exception caught";
}
}
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我有几个 ajax 全局事件。
在
$(document).ajaxSend(function(event, jqxhr, settings) {
//
});
Run Code Online (Sandbox Code Playgroud)
我可以从以下位置获取请求的网址settings.url
但是我怎样才能从这个请求的响应中获取url
$(document).ajaxComplete(function (e, jqxhr) {
//
});
Run Code Online (Sandbox Code Playgroud)
这里包含请求的 url 的唯一对象是arguments[2].url
有没有其他方法可以从响应中获取请求的 url,因为我不确定这样的对象arguments[2].url?
在我的MVC解决方案中,我有两个处理程序用于例外.首先记录Logs数据库的异常:
public sealed class LogErrorAttribute : Attribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
// some handling with filterContext.Exception
}
}
Run Code Online (Sandbox Code Playgroud)
第二个显示用户异常:
public sealed class AsyncAwareHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
// some handling with filterContext.Exception
}
}
Run Code Online (Sandbox Code Playgroud)
当发生任何未处理的异常时,它们都会被触发:
throw new ArgumentNullException("email", i18n.someErrorMessage);
Run Code Online (Sandbox Code Playgroud)
i18n.someErrorMessage是从resx文件中翻译的字符串.
在两个处理程序中filterContext.Exception.Message我都有已经翻译过的字符串.
如何仅在我的解决方案中CultureInfo.InvariantCulture设置了异常消息en-US?
c# error-logging exception-handling internationalization asp.net-mvc-4
我有一个 ASP.NET Core 沙箱项目。我已经添加了IdentityDbContext。注册页面工作正常。登录/注销页面工作正常。(可以通过为SignInManager.IsSignedIn(User)用户显示的html看到)
我有一个控制器标有[Authorize]:
[Authorize]
public class MyTestController : Controller
{
...
}
Run Code Online (Sandbox Code Playgroud)
当我第一次尝试导航到它时 - 它工作正常(重定向到登录页面)
但成功登录后,它再次重定向回使用相同链接登录: https://localhost:44359/Identity/Account/Login?ReturnUrl=%2FMyTest
这是我的代码Startup.cs:
[Authorize]
public class MyTestController : Controller
{
...
}
Run Code Online (Sandbox Code Playgroud)
以前,我为登录、注销、注册添加了脚手架身份项。没有[Authorize]工作良好的控制器。