本文整理汇总了C#中System.Net.HttpListenerContext.SetStatusToBadRequest方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerContext.SetStatusToBadRequest方法的具体用法?C# HttpListenerContext.SetStatusToBadRequest怎么用?C# HttpListenerContext.SetStatusToBadRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpListenerContext
的用法示例。
在下文中一共展示了HttpListenerContext.SetStatusToBadRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Put
private void Put(HttpListenerContext context, string index)
{
var data = context.ReadJsonObject<IndexDefinition>();
if (data.Map == null)
{
context.SetStatusToBadRequest();
context.Write("Expected json document with 'Map' property");
return;
}
context.SetStatusToCreated("/indexes/" + index);
context.WriteJson(new { index = Database.PutIndex(index, data) });
}
示例2: HandleBadRequest
private static void HandleBadRequest(HttpListenerContext ctx, BadRequestException e)
{
ctx.SetStatusToBadRequest();
using (var sw = new StreamWriter(ctx.Response.OutputStream))
{
new JsonSerializer().Serialize(sw,
new
{
url = ctx.Request.RawUrl,
message = e.Message,
error = e.Message
});
}
}
示例3: HandleRequest
private void HandleRequest(HttpListenerContext ctx)
{
if (AssertSecurityRights(ctx) == false)
return;
foreach (var requestResponder in requestResponders)
{
if (requestResponder.WillRespond(ctx))
{
requestResponder.Respond(ctx);
return;
}
}
ctx.SetStatusToBadRequest();
ctx.Write(
@"
<html>
<body>
<h1>Could not figure out what to do</h1>
<p>Your request didn't match anything that Raven knows to do, sorry...</p>
</body>
</html>
");
}