HttpContext.Current.IsDebuggingEnabled始终为true

时间:2014-03-09 18:30:11

标签: configuration appharbor

为什么我的网站正在运行调试模式?

HttpContext.Current.IsDebuggingEnabled总是如此!

捆绑无效!

虽然#if DEBUG为false,但未定义DEBUG!

我的appharbor应用程序已启用预编译。

在我的Web.Release.config中删除debug:

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

Online Transformation Tester通过我的Web.config和Web.Release.config测试了这个结果:

<?xml version="1.0"?>
<!--
  Para obtener más información sobre cómo configurar la aplicación de ASP.NET, visite
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=9831a429-a608-4055-8bb9-a2bb016f79a3.sqlserver.sequelizer.com;Initial Catalog=db9831a429a60840558bb9a2bb016f79a3;user id=wgomqcwgmezvqifh;password=JqgJKAdNmPvR6ZSwsVJYZtP7VYE2pZaTmn6Mntozm4r8TjtMAEFZRwzqHhVT4kxu;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
    <add name="StorageConnectionString" connectionString="UseDevelopmentStorage=true" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="TwitterKey" value="{TwitterKey}" />
    <add key="TwitterSecret" value="{TwitterSecret}" />
    <add key="FacebookKey" value="{FacebookKey}" />
    <add key="FacebookSecret" value="{FacebookSecret}" />
    <add key="MicrosoftKey" value="{MicrosoftKey}" />
    <add key="MicrosoftSecret" value="{MicrosoftSecret}" />
    <add key="AnalyticsCode" value="{AnalyticsCode}" />
    <add key="AnalyticsDomain" value="{AnalyticsDomain}" />
    <add key="CrawlerServiceApiId" value="{CrawlerServiceApiId}" />
    <add key="CrawlerServiceApplication" value="{CrawlerServiceApplication}" />
    <add key="CrawlerServiceEndPoint" value="{CrawlerServiceEndPoint}" />
    <add key="EmailServer" value="{EmailServer}" />
    <add key="EmailUser" value="{EmailUser}" />
    <add key="EmailPassword" value="{EmailPassword}" />
  </appSettings>
  <system.web>
    <authentication mode="None" />
    <compilation targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
    </staticContent>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31BF3856AD364E35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

2 个答案:

答案 0 :(得分:1)

从Visual Studio进行调试时,不会应用您的web.config转换。这意味着您的默认Web.config可能包含行<compilation debug="true" targetFramework="4.6.1"/>,强调debug="true"

从基本Web.config文件中的编译元素中删除debug="true"属性将使HttpContext.Current.IsDebuggingEnabled等于false。

其他一些选项:如果您要查看请求是否来自本地计算机,则可以检查Request.IsLocal而不是HttpContext.Current.IsDebuggingEnabled,或检查有效的调试程序{{1} }

答案 1 :(得分:0)

我有同样的问题。 暂时,我使用了http://support.appharbor.com/kb/getting-started/managing-environments中的解决方法。

<add key="Environment" value="Debug"/>

Appharbor将替换值=&#34; Debug&#34;到AppHarbor https://appharbor.com/applications/ {appname} / edit

中设置的环境

我没有检查HttpContext.IsDebugingEnabled,而是检查

var isInDebugMode = ConfigurationManager.AppSettings["Environment"].Equals("Debug", StringComparison.InvariantCultureIgnoreCase));