替代CustomErrors模式=“ RemoteOnly”;在Asp.NetCore Web应用程序中 [英] Alternate for CustomErrors Mode = "RemoteOnly" in Asp.NetCore web applications

查看:181
本文介绍了替代CustomErrors模式=“ RemoteOnly”;在Asp.NetCore Web应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AspNet Core Web应用程序,仅当有人远程访问该应用程序时,我才想显示自定义错误。如果要在本地访问此应用程序,我想为开发人员保留详细的错误页面。在.netFramework 4.x和更早版本中,我们可以在web.config customErrors属性中使用mode = RemoteOnly进行指定。我知道以下事实:我们可以使ASPNETCORE_ENVIRONMENT变量的用户打开aspnetcore中的自定义错误或开发人员异常页面。但是我要寻找的是-在AspNetCore中具有CustomErrors模式= RemoteOnly的类似功能。

I have an AspNet Core web application, in which I want to show custom errors only when someone is accessing the application remotely. In case this application is being accessed locally ,i want to keep the detailed error page for the developer. In .netFramework 4.x and earlier, we were able to specify this in web.config customErrors property with mode=RemoteOnly. I am aware about the fact that we can make user of ASPNETCORE_ENVIRONMENT variable to turn on custom error or developer exception page in aspnetcore. But what I am looking for is -to have similar functionality for CustomErrors mode = RemoteOnly in AspNetCore.

推荐答案

直接回答您的问题,我认为Web.config中没有CustomErrors键的直接替代。但是,IHostingEnvironment界面上还有其他几种方法可以使用,具体取决于您要实现的方法。例如,您可以检查多个环境:

To answer your question directly, I don't believe there is an straight forward replacement for CustomErrors key in the Web.config. However, there are a few more methods available on the IHostingEnvironment interface that may be of use for you depending on what you're trying to implement. For example you could check multiple environments:

if (env.IsProduction() || env.IsStaging() || env.IsEnvironment("Staging_2"))
{
    // Handle the custom errors here
}

关于实现特定于环境的功能的不同方法,有不错的文档此处

There is decent documentation on different ways to implement environment specific features here.

这篇关于替代CustomErrors模式=“ RemoteOnly”;在Asp.NetCore Web应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆