本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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>
");
}
示例5: SerializeError
static void SerializeError(IHttpContext ctx, object error)
{
ctx.WriteString(error.ToString());
//JsonSerializer.SerializeToStream(error,ctx.Response.OutputStream);
}