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


C# IHttpContext.WriteString方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: SerializeError

 static void SerializeError(IHttpContext ctx, object error)
 {
     ctx.WriteString(error.ToString());
     //JsonSerializer.SerializeToStream(error,ctx.Response.OutputStream);
 }
开发者ID:JeetKunDoug,项目名称:lokad-cqrs,代码行数:5,代码来源:Listener.cs


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