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


C# IHttpContext.SetStatusTo方法代码示例

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


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

示例1: ProcessRequestInner

        public void ProcessRequestInner(IHttpContext context)
        {
            var sw = Stopwatch.StartNew();

            try
            {
                DispatchRequestToHandlers(context);
            }
            catch (Exception e)
            {
                HandleException(context, e);

                context.SetStatusTo(HttpStatusCode.InternalServerError);

            }
            finally
            {
                context.TryCloseResponse();

                var curReq = Interlocked.Increment(ref _requestNumber);
                Trace.WriteLine(string.Format("Request #{0,4:#,0}: {1,-7} - {2,5:#,0} ms - {3} - {4}",
                    curReq, context.Request.HttpMethod, sw.ElapsedMilliseconds, context.Response.StatusCode,
                    context.Request.Url.PathAndQuery));
            }
        }
开发者ID:JeetKunDoug,项目名称:lokad-cqrs,代码行数:25,代码来源:Listener.cs

示例2: Handle

 public override void Handle(IHttpContext context)
 {
     var stream = context.Response.OutputStream;
     Resources.favicon.Save(stream);
     stream.Flush();
     context.SetStatusTo(HttpStatusCode.OK);
 }
开发者ID:JeetKunDoug,项目名称:lokad-cqrs,代码行数:7,代码来源:FaviconHttpRequestHandler.cs

示例3: Handle

        public override void Handle(IHttpContext context)
        {
            _mouseStats.RefreshStatistics();

            var data =  JsonSerializer.SerializeToString(_mouseStats);

            context.Response.ContentType = "application/json";

            context.WriteString(data);
            context.SetStatusTo(HttpStatusCode.OK);
        }
开发者ID:JeetKunDoug,项目名称:lokad-cqrs,代码行数:11,代码来源:MouseStatsRequestHandler.cs

示例4: Handle

        public override void Handle(IHttpContext context)
        {
            var msg = new EnvelopeBuilder(Guid.NewGuid().ToString());

            var contract = context.GetRequestUrl().Remove(0,"/send/".Length);
            Type contractType;
            if (!_serializer.TryGetContractTypeByName(contract, out contractType))
            {
                context.WriteString(string.Format("Trying to post command with unknown contract '{0}'.", contract));
                context.SetStatusTo(HttpStatusCode.BadRequest);
                return;
            }

            _writer.PutMessage(_streamer.SaveEnvelopeData(msg.Build()));
            context.WriteString(string.Format(@"
            Normally this should be a JSON POST, containing serialized data for {0}
            but let's pretend that you successfully sent a message. Or routed it", contractType));

            context.SetStatusTo(HttpStatusCode.OK);
        }
开发者ID:kmaclean,项目名称:lokad-cqrs,代码行数:20,代码来源:MyAnonymousCommandSender.cs

示例5: Handle

        public override void Handle(IHttpContext context)
        {
            var contract = context.GetRequestUrl().Remove(0, "/mouseevents/".Length);

            var envelopeBuilder = new EnvelopeBuilder(contract + " - " + DateTime.Now.Ticks.ToString());

            Type contractType;
            if (!_serializer.TryGetContractTypeByName(contract, out contractType))
            {
                context.WriteString(string.Format("Trying to post command with unknown contract '{0}'.", contract));
                context.SetStatusTo(HttpStatusCode.BadRequest);
                return;
            }

            var decodedData = HttpUtility.UrlDecode(context.Request.QueryString.ToString());
            var mouseEvent = JsonSerializer.DeserializeFromString(decodedData, contractType);

            envelopeBuilder.AddItem(mouseEvent);
            _writer.PutMessage(_streamer.SaveEnvelopeData(envelopeBuilder.Build()));

            context.SetStatusTo(HttpStatusCode.OK);
        }
开发者ID:kmaclean,项目名称:lokad-cqrs,代码行数:22,代码来源:MouseEventsRequestHandler.cs

示例6: Handle

        public override void Handle(IHttpContext context)
        {
            var view = _reader.Get(unit.it);

            if (view.HasValue)
            {
                if (context.GetRequestUrl().Contains("thumb"))
                {
                    view.Value.Thumbnail.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                }
                else
                {
                    view.Value.Heatmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                }
            }
            else
            {
                ReturnEmptyImage(context);
            }

            context.SetStatusTo(HttpStatusCode.OK);
        }
开发者ID:JeetKunDoug,项目名称:lokad-cqrs,代码行数:22,代码来源:HeatMapRequestHandler.cs

示例7: DispatchRequestToHandlers

        void DispatchRequestToHandlers(IHttpContext context)
        {
            foreach (var requestResponder in _handlers)
            {
                if (requestResponder.WillHandle(context))
                {
                    requestResponder.Handle(context);
                    return;
                }
            }
            context.SetStatusTo(HttpStatusCode.BadRequest);

            if (context.Request.HttpMethod == "HEAD")
                return;
            context.WriteString(
                @"
            <html>
            <body>
            <h1>Bad Request</h1>
            <p>Mea culpa, <a href='http://lokad.github.com/lokad-cqrs/'>Lokad.Cqrs</a> Http server
            does not know, how to handle this request.</p>
            </body>
            </html>
            ");
        }
开发者ID:JeetKunDoug,项目名称:lokad-cqrs,代码行数:25,代码来源:Listener.cs


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