【问题标题】:How to turn custom errors off when deploying to azure in debug mode only仅在调试模式下部署到 Azure 时如何关闭自定义错误
【发布时间】:2016-04-21 01:39:11
【问题描述】:

我正在一个网站上工作,我们使用 Web.Debug.config 和转换 XSLT 来关闭自定义错误

<customErrors mode="Off" xdt:Transform="Replace"/>`

但是在部署到 azure 时似乎没有考虑到这一点。

来自

Azure web.config per environment

我可以看到 azure 使用 .cscfg 文件,而我要完成的工作可能会涉及这些文件?部署到天蓝色但仅在调试时关闭自定义错误的最简单方法是什么?

【问题讨论】:

    标签: asp.net azure


    【解决方案1】:

    从 Visual Studio 2015 开始,对于“应用服务”,打开服务器资源管理器并导航到 Azure -> 应用服务 -> {资源组名称} -> {应用服务名称} -> 文件 -> Web.config。

    此时,您可以直接编辑 Web.Config 文件并保存 - 无需发布。

    【讨论】:

      【解决方案2】:

      但是在部署到 azure 时似乎没有考虑到这一点

      可能是因为您的普通 web.config 不包含元素(我今天遇到了同样的问题)。当然,只有在确实有要应用的东西时才能应用您对“替换”的转换。

      部署到 azure 但仅在调试时关闭自定义错误的最简单方法是什么?

      有一个 debug web.config 和一个 release web.config(你可以扩展 web.config)。在第一版中应用生产转换,在调试版中应用调试转换。

      【讨论】:

      • 是的,但他可以为打包创建一个新的构建配置。
      【解决方案3】:

      事实上,您将添加到 web.release.config 或 web.debug.config 的任何内容都不会包含在最终的 web.config 中,最终的 web.config 将成为部署到 Windows Azure 的应用程序包 (CSPKG) 的一部分。如果您希望将某些 web.config 设置作为 Windows Azure 应用程序的一部分,则必须在 web.config 中显式定义。

      要关闭自定义错误,您可以在 web.config 中显式添加以下内容:

      <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        ......
        <system.web>
         <customErrors mode="Off" xdt:Transform="Replace"/>
        </system.web>
       .....
      </configuration>
      

      【讨论】:

      • 所以当部署到天蓝色时它会忽略转换?有点迷茫,你给的代码示例是变换?
      • 不,他是说 web.debug.config 和 web.release.config 没有被考虑在内。
      【解决方案4】:

      您需要在 web.config

      中有这一行
      <customErrors mode="Off"/>
      

      而在 web.config.release

      <system.web>
           <customErrors mode="Off" xdt:Transform="Replace"/> 
          <compilation xdt:Transform="RemoveAttributes(debug)" />    
        </system.web>
      

      当使用一键发布时,它将从 web.config.release 替换为 web.config 因此,如果 web.config 没有 customErrors 标签,它将忽略

      【讨论】:

        猜你喜欢
        • 2010-09-11
        • 1970-01-01
        • 1970-01-01
        • 2013-11-28
        • 2014-06-27
        • 1970-01-01
        • 1970-01-01
        • 2015-04-06
        • 2014-02-08
        相关资源
        最近更新 更多