c# - 如何从代码中获取 customErrors 的 defaultRedirect 值?

标签 c# .net asp.net-mvc web-config custom-errors

我只想做如下事情:

var defaultRedirectUrl = SomeMethodToGetDefaultRedirect();

当然在 web.config 中我有

<customErrors mode="On" defaultRedirect="~/Error"/>

如何做到这一点?

最佳答案

谢谢马克,很有帮助。 我真正想问的是“如何从我的 asp mvc 应用程序的 web.config 中获取 customErrors 部分的“defaultRedirect”属性?”。

根据您的帖子,答案是:

    CustomErrorsSection customErrorsSection = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors");
        string defaultRedirect = customErrorsSection.DefaultRedirect;

关于c# - 如何从代码中获取 customErrors 的 defaultRedirect 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10507939/

相关文章:

c# - 不同种子的 O log(N) 中的斐波那契数列

c# - 实现的PIA接口(interface)有回调,找不到定义

c# - Directory.GetCurrentDirectory() 不适用于 Linux?

c# - .NET 中的 UI 测试自动化

javascript - 导航工具栏中的jqGrid添加按钮不起作用

c# - 有什么办法可以绕过 RenderBody() 要求吗?

c# - 使用MYSQL数据库时Request.IsAuthenticated false : MVC5

c# - 如何根据分钟舍入小时数(如果分钟<30,小时+0,否则小时+1)?

c# - 正确处理单例 IDisposable 对象

c# - .NET Core - 在 C# 代码中获取项目描述