Beispiel #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();
            }
        }
        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();
            }
        }
        internal void SetNoDemand(String name, String value)
        {
            if (value == null)
            {
                value = String.Empty;
            }

            _iis7workerRequest.SetServerVariable(name, value);
            SetServerVariableManagedOnly(name, value);
            SynchronizeHeader(name, value);
            _request.InvalidateParams();
        }