【问题标题】:Asp.net - <customErrors mode="Off"/> error when trying to access working webpageAsp.net - 尝试访问工作网页时出现 <customErrors mode="Off"/> 错误
【发布时间】:2011-05-20 19:41:47
【问题描述】:

我创建了一个 asp.net 网页并将其上传到网络服务器。但是,当我尝试远程查看页面时,我在 web.config 文件中收到有关 customerror 标记的错误。该页面在本地工作,没有错误或警告。此外,如果我将页面作为 .html 文件上传,我可以远程查看它。 我见过很多其他人遇到此错误,但“解决方案”只是说将 customErrors 标记更改为“关闭”,我已经完成但不起作用,你知道网络服务器有问题还是什么可能是这里的问题吗?

这是错误页面:

“/”应用程序中的服务器错误。 运行时错误 说明:服务器上发生应用程序错误。此应用程序的当前自定义错误 > 设置阻止远程查看应用程序错误的详细信息(出于安全原因)。但是,它可以被>本地服务器机器上运行的浏览器查看。

详细信息:要在远程机器上查看此特定错误消息的详细信息,请在位于当前 Web 应用程序根目录的“web.config”配置文件中创建一个标签。该标签 > 应将其“模式”属性设置为“关闭”。

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

注意:您看到的当前错误页面可以通过>修改应用程序的>configuration标签的“defaultRedirect”属性以指向自定义错误页面URL来替换为自定义错误页面。

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>

这是我的 web.config 文件:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <customErrors mode="Off"/>
  </system.web>

  <system.web>
    <compilation debug="true"/>
    <authentication mode="None"/>
  </system.web>
</configuration>

【问题讨论】:

  • @jvanrhyn 可能发现了你的问题。如果没有,请检查:stackoverflow.com/questions/2830361/…
  • 我让页面远程工作,有 2 个 web.config 文件,我在“帐户”文件夹中更改了错误的文件。我应该一直在更改项目根目录中的那个,但愚蠢地没有看到它。 jvanrhyn 关于一个 标签也是正确的,谢谢。

标签: asp.net web-config webserver custom-errors


【解决方案1】:

您的Web.Config Configuration File 中应该只有一个&lt;system.web&gt;

<?xml version="1.0"?>
<configuration>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true"/>
    <authentication mode="None"/>
  </system.web>
</configuration>

【讨论】:

  • 另外值得注意的是,“关闭”是区分大小写的,因为我在尝试解决相同问题 20 分钟后才发现
【解决方案2】:

这些解决方案都不适合我,但我的 web.config 中有这个

<log4net debug="true">

要么删除所有这些,要么去阅读应用程序文件夹\logs 中的错误日志

【讨论】:

    【解决方案3】:

    未来的某个时候 在 web.config 中注释掉以下代码

     <!--<system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
      </system.codedom>-->
    

    更新为以下代码。

    <system.web>
        <authentication mode="None" />
        <compilation debug="true" targetFramework="4.6.1" />
        <httpRuntime targetFramework="4.6.1" />
        <customErrors mode="Off"/>
        <trust level="Full"/>
      </system.web>
    

    【讨论】:

    • 为什么建议更改 .NET 框架版本或身份验证模式?这些与解决问题有什么关系?
    【解决方案4】:

    例如,在我的情况下,我不小心将某些用户的角色更改为不正确的,并且我的应用程序在启动过程中出错(NullReferenceException)。当我修复它时 - 应用程序启动正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多