当前位置: 首页>>代码示例>>C#>>正文


C# Response.AppendHeader方法代码示例

本文整理汇总了C#中Response.AppendHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Response.AppendHeader方法的具体用法?C# Response.AppendHeader怎么用?C# Response.AppendHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Response的用法示例。


在下文中一共展示了Response.AppendHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Handle


//.........这里部分代码省略.........
            // specifications and must not be used otherwise. 
            
            // noop

            // The environment 
            // must not contain the keys HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH 
            // (use the versions without HTTP_). The CGI keys (named without a period)
            // must have String values.

            RemoveEnv(env, "HTTP_CONTENT_LENGTH");
            RemoveEnv(env, "HTTP_CONTENT_TYPE");

            // Set other vars based on what WEBrick sets:

            SetEnv(env, "REMOTE_HOST", request.OrigionalRequest.Url.Host);
            SetEnv(env, "SERVER_PROTOCOL", request.OrigionalRequest.Params["SERVER_PROTOCOL"]);
            SetEnv(env, "REQUEST_PATH", request.OrigionalRequest.Path);
            SetEnv(env, "SERVER_SOFTWARE", request.OrigionalRequest.Params["SERVER_SOFTWARE"]);
            SetEnv(env, "REMOTE_ADDR", "127.0.0.1");
            SetEnv(env, "HTTP_VERSION", request.OrigionalRequest.Params["SERVER_PROTOCOL"]);
            SetEnv(env, "REQUEST_URI", request.OrigionalRequest.Url.AbsoluteUri);
            SetEnv(env, "GATEWAY_INTERFACE", request.OrigionalRequest.Params["GATEWAY_INTERFACE"]);

            // A Rack application is an Ruby object (not a class) that responds
            // to call. It takes exactly one argument, the environment and 
            // returns an Array of exactly three values: The status, the headers, 
            // and the body.

            RubyArray ruby_response = App.Call(env);

            try {
                // The Response
                // ============
                
                // The Status
                // ----------
                // This is an HTTP status. When parsed as integer (to_i), it
                // must be greater than or equal to 100.
                
                response.Status = (int)ruby_response[0];

                // The Headers
                // -----------
                // The header must respond to each, and yield values of key and
                // value. The header keys must be Strings. The header must not
                // contain a Status key, contain keys with : or newlines in 
                // their name, contain keys names that end in - or _, but only 
                // contain keys that consist of letters, digits, _ or - and 
                // start with a letter. The values of the header must be 
                // Strings, consisting of lines (for multiple header values, 
                // e.g. multiple Set-Cookie values) seperated by “n“. The lines
                // must not contain characters below 037.
                
                foreach (var header in ((Hash)ruby_response[1])) {
                    foreach (var value in header.Value.ToString().Split('\n')) {
                        response.AppendHeader(header.Key.ToString(), value.ToString());
                    }
                }
                
                // The Content-Type
                // ----------------
                // There must be a Content-Type, except when the Status is 1xx,
                // 204 or 304, in which case there must be none given.

                // TODO

                // The Content-Length
                // ------------------
                // There must not be a Content-Length header when the Status is
                // 1xx, 204 or 304.
            
                // TODO
    
                // The Body
                // --------
                // The Body must respond to each and must only yield String 
                // values. The Body itself should not be an instance of String,
                // as this will break in Ruby 1.9. If the Body responds to
                // close, it will be called after iteration. If the Body
                // responds to to_path, it must return a String identifying the
                // location of a file whose contents are identical to that
                // produced by calling each; this may be used by the server as
                // an alternative, possibly more efficient way to transport the 
                // response. The Body commonly is an Array of Strings, the
                // application instance itself, or a File-like object.


                handle_scope.SetVariable("__body", ruby_response[2]);
                RubyEngine.Execute(@"
                    __body.each do |part| 
                        __response.write part 
                    end
                    ", handle_scope);

            } finally {
                RubyEngine.Execute(@"
                    __body.close if __body.respond_to? :close
                    ", handle_scope);
            }
        }
开发者ID:BenHall,项目名称:ironruby,代码行数:101,代码来源:IIS.cs


注:本文中的Response.AppendHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。