本文整理汇总了C#中System.Net.HttpListenerContext.SetStatusToNotModified方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerContext.SetStatusToNotModified方法的具体用法?C# HttpListenerContext.SetStatusToNotModified怎么用?C# HttpListenerContext.SetStatusToNotModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpListenerContext
的用法示例。
在下文中一共展示了HttpListenerContext.SetStatusToNotModified方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Respond
public override void Respond(HttpListenerContext context)
{
var match = urlMatcher.Match(context.Request.Url.LocalPath);
var filename = match.Groups[1].Value;
var etag = context.GetEtag();
switch (context.Request.HttpMethod)
{
case "GET":
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteData(attachmentAndHeaders.Data, attachmentAndHeaders.Metadata,
attachmentAndHeaders.Etag);
break;
case "PUT":
Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream.ReadData(),
context.Request.Headers.FilterHeaders());
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例2: Respond
public override void Respond(HttpListenerContext context)
{
var match = urlMatcher.Match(context.Request.Url.LocalPath);
var docId = match.Groups[1].Value;
switch (context.Request.HttpMethod)
{
case "GET":
context.Response.Headers["Content-Type"] = "application/json; charset=utf-8";
var doc = Database.Get(docId,GetRequestTransaction(context));
if (doc == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(doc.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteData(doc.Data, doc.Metadata, doc.Etag);
break;
case "DELETE":
Database.Delete(docId, context.GetEtag(), GetRequestTransaction(context));
context.SetStatusToDeleted();
break;
case "PUT":
Put(context, docId);
break;
case "PATCH":
var patchDoc = context.ReadJsonArray();
var patchResult = Database.ApplyPatch(docId, context.GetEtag(), patchDoc, GetRequestTransaction(context));
switch (patchResult)
{
case PatchResult.DocumentDoesNotExists:
context.SetStatusToNotFound();
break;
case PatchResult.Patched:
context.WriteJson(new {patched = true});
break;
default:
throw new ArgumentOutOfRangeException("Value " + patchResult + " is not understood");
}
break;
}
}