示例#1
0
 public override void Remove(string name)
 {
     if (this._iis7WorkerRequest == null)
     {
         throw new PlatformNotSupportedException();
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (this._request != null)
     {
         this._iis7WorkerRequest.SetRequestHeader(name, null, false);
     }
     else
     {
         this._iis7WorkerRequest.SetResponseHeader(name, null, false);
     }
     base.Remove(name);
     if (this._request != null)
     {
         HttpServerVarsCollection serverVariables = this._request.ServerVariables as HttpServerVarsCollection;
         if (serverVariables != null)
         {
             serverVariables.SynchronizeServerVariable("HTTP_" + name.ToUpper(CultureInfo.InvariantCulture).Replace('-', '_'), null);
         }
         this._request.InvalidateParams();
     }
 }
示例#2
0
        internal void SetHeader(String name, String value, bool replace)
        {
            Debug.Assert(_iis7WorkerRequest != null, "_iis7WorkerRequest != null");

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (_request != null)
            {
                _iis7WorkerRequest.SetRequestHeader(name, value, replace);
            }
            else
            {
                if (_response.HeadersWritten)
                {
                    throw new HttpException(SR.GetString(SR.Cannot_append_header_after_headers_sent));
                }

                // set the header encoding to the selected encoding
                _iis7WorkerRequest.SetHeaderEncoding(_response.HeaderEncoding);

                _iis7WorkerRequest.SetResponseHeader(name, value, replace);

                if (_response.HasCachePolicy && StringUtil.EqualsIgnoreCase("Set-Cookie", name))
                {
                    _response.Cache.SetHasSetCookieHeader();
                }
            }

            // update managed copy of header
            if (replace)
            {
                base.Set(name, value);
            }
            else
            {
                base.Add(name, value);
            }

            if (_request != null)
            {
                // update managed copy of server variable
                string svValue = replace ? value : base.Get(name);
                HttpServerVarsCollection serverVars = _request.ServerVariables as HttpServerVarsCollection;
                if (serverVars != null)
                {
                    serverVars.SynchronizeServerVariable("HTTP_" + name.ToUpper(CultureInfo.InvariantCulture).Replace('-', '_'), svValue);
                }

                // invalidate Params collection
                _request.InvalidateParams();
            }
        }
        public override void Remove(String name) {
            if (_iis7WorkerRequest == null) {
                throw new PlatformNotSupportedException();
            }

            if (name == null) {
                throw new ArgumentNullException("name");
            }           

            if (_request != null) {
                // delete by sending null value
                _iis7WorkerRequest.SetRequestHeader(name, null /*value*/, false /*replace*/);
            }
            else {
                _iis7WorkerRequest.SetResponseHeader(name, null /*value*/, false /*replace*/);
            }

            base.Remove(name);
            if (_request != null) {
                // update managed copy of server variable
                HttpServerVarsCollection serverVars = _request.ServerVariables as HttpServerVarsCollection;
                if (serverVars != null) {
                    serverVars.SynchronizeServerVariable("HTTP_" + name.ToUpper(CultureInfo.InvariantCulture).Replace('-', '_'), null);
                }

                // invalidate Params collection
                _request.InvalidateParams();
            }
        }
        internal void SetHeader(String name, String value, bool replace) {
            Debug.Assert(_iis7WorkerRequest != null, "_iis7WorkerRequest != null");

            if (name == null) {
                throw new ArgumentNullException("name"); 
            }
            
            if (value == null) {
                throw new ArgumentNullException("value");
            }

            if (_request != null) {
                _iis7WorkerRequest.SetRequestHeader(name, value, replace);
            }
            else {
                if (_response.HeadersWritten) {
                    throw new HttpException(SR.GetString(SR.Cannot_append_header_after_headers_sent));
                }

                // IIS7 integrated pipeline mode needs to call the header encoding routine explicitly since it
                // doesn't go through HttpResponse.WriteHeaders().
                string encodedName = name;
                string encodedValue = value;
                if (HttpRuntime.EnableHeaderChecking) {
                    HttpEncoder.Current.HeaderNameValueEncode(name, value, out encodedName, out encodedValue);
                }
                
                // set the header encoding to the selected encoding
                _iis7WorkerRequest.SetHeaderEncoding(_response.HeaderEncoding);

                _iis7WorkerRequest.SetResponseHeader(encodedName, encodedValue, replace);

                if (_response.HasCachePolicy && StringUtil.EqualsIgnoreCase("Set-Cookie", name)) {
                    _response.Cache.SetHasSetCookieHeader();
                }
            }
            
            // update managed copy of header
            if (replace) {
                base.Set(name, value);
            }
            else {
                base.Add(name, value);
            }

            if (_request != null) {
                // update managed copy of server variable
                string svValue = replace ? value : base.Get(name);
                HttpServerVarsCollection serverVars = _request.ServerVariables as HttpServerVarsCollection;
                if (serverVars != null) {
                    serverVars.SynchronizeServerVariable("HTTP_" + name.ToUpper(CultureInfo.InvariantCulture).Replace('-', '_'), svValue);
                }

                // invalidate Params collection
                _request.InvalidateParams();
            }
        }
示例#5
0
 internal void SetHeader(string name, string value, bool replace)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (this._request != null)
     {
         this._iis7WorkerRequest.SetRequestHeader(name, value, replace);
     }
     else
     {
         if (this._response.HeadersWritten)
         {
             throw new HttpException(System.Web.SR.GetString("Cannot_append_header_after_headers_sent"));
         }
         string encodedHeaderName  = name;
         string encodedHeaderValue = value;
         if (HttpRuntime.EnableHeaderChecking)
         {
             HttpEncoder.Current.HeaderNameValueEncode(name, value, out encodedHeaderName, out encodedHeaderValue);
         }
         this._iis7WorkerRequest.SetHeaderEncoding(this._response.HeaderEncoding);
         this._iis7WorkerRequest.SetResponseHeader(encodedHeaderName, encodedHeaderValue, replace);
         if (this._response.HasCachePolicy && StringUtil.EqualsIgnoreCase("Set-Cookie", name))
         {
             this._response.Cache.SetHasSetCookieHeader();
         }
     }
     if (replace)
     {
         base.Set(name, value);
     }
     else
     {
         base.Add(name, value);
     }
     if (this._request != null)
     {
         string str3 = replace ? value : base.Get(name);
         HttpServerVarsCollection serverVariables = this._request.ServerVariables as HttpServerVarsCollection;
         if (serverVariables != null)
         {
             serverVariables.SynchronizeServerVariable("HTTP_" + name.ToUpper(CultureInfo.InvariantCulture).Replace('-', '_'), str3);
         }
         this._request.InvalidateParams();
     }
 }