2013-06-21 1 views
3

응용 프로그램을 시작할 때 Null 참조 예외가 발생합니다. 다음은 HttpContext.Current null입니다.HttpContext.Current가 Application_PreSendRequestHeaders에서 null입니다.

protected void Application_PreSendRequestHeaders() 
{ 
    HttpResponse response = HttpContext.Current.Response; 
    if (response.Filter is GZipStream && response.Headers["Content-encoding"] != "gzip") 
    { 
     response.AppendHeader("Content-encoding", "gzip"); 
    } 
    else if (response.Filter is DeflateStream && response.Headers["Content-encoding"] != "deflate") 
    { 
     response.AppendHeader("Content-encoding", "deflate"); 
    } 
} 

왜 그렇고 어떻게 작동합니까?

답변

1

최근에 VS 2008에서 VS 2012로 업그레이드 했습니까?

나는 여전히 web.config 파일을 업그레이드해야한다고 생각합니다. <system.web>에 다음 섹션을 추가)

<compilation debug="true" targetFramework="4.5"> 

3 :

<membership> 
    <providers> 
    <clear /> 
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/" /> 
    </providers> 
</membership> 
<profile> 
    <providers> 
    <clear /> 
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/" /> 
    </providers> 
</profile> 
<roleManager enabled="false"> 
    <providers> 
    <clear /> 
    <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </providers> 
</roleManager> 
<compilation> 태그 추가 속성 targetFramework="4.5"에서

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
    <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> 
     <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
     <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
     <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
    </sectionGroup> 
    </sectionGroup> 
</sectionGroup> 

2) :

1) <configSections>에서이 부분을 제거

4) 섹션의 <httpHandlers><httpModules> 섹션

5) <system.codedom> 섹션을 제거하십시오.

+0

이유에 대해 설명해 주시겠습니까? – Josh

+0

정확히 이유를 모르겠지만 VS 2012로 업그레이드하고 Web.config를 업데이트하지 않았을 때 Djave와 동일한 문제가있었습니다. –

0

이 문제는 응용 프로그램 풀의 "Managed pipeline mode"설정을 classic에서 Integrated로 변경 한 후에 수정되었습니다.

관련 문제