Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        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();
            }
        }