本文整理汇总了C#中IHttpContext.SetStatusToNonAuthoritiveInformation方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.SetStatusToNonAuthoritiveInformation方法的具体用法?C# IHttpContext.SetStatusToNonAuthoritiveInformation怎么用?C# IHttpContext.SetStatusToNonAuthoritiveInformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.SetStatusToNonAuthoritiveInformation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
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(doc.NonAuthoritiveInformation)
{
context.SetStatusToNonAuthoritiveInformation();
}
if (context.MatchEtag(doc.Etag))
{
context.SetStatusToNotModified();
return;
}
doc.Metadata["Last-Modified"] = doc.LastModified.ToString("r");
context.WriteData(doc.DataAsJson, 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 patchRequestJson = context.ReadJsonArray();
var patchRequests = patchRequestJson.Cast<JObject>().Select(PatchRequest.FromJson).ToArray();
var patchResult = Database.ApplyPatch(docId, context.GetEtag(), patchRequests, GetRequestTransaction(context));
switch (patchResult)
{
case PatchResult.DocumentDoesNotExists:
context.SetStatusToNotFound();
break;
case PatchResult.Patched:
context.Response.Headers["Location"] = Database.Configuration.GetFullUrl("/docs/" + docId);
context.WriteJson(new {Patched = true});
break;
default:
throw new ArgumentOutOfRangeException("Value " + patchResult + " is not understood");
}
break;
}
}
示例2: Get
private void Get(IHttpContext context, string docId)
{
context.Response.AddHeader("Content-Type", "application/json; charset=utf-8");
if (string.IsNullOrEmpty(context.Request.Headers["If-None-Match"]))
{
GetDocumentDirectly(context, docId);
return;
}
Database.TransactionalStorage.Batch(
_ => // we are running this here to ensure transactional safety for the two operations
{
var transactionInformation = GetRequestTransaction(context);
var documentMetadata = Database.GetDocumentMetadata(docId, transactionInformation);
if (documentMetadata == null)
{
context.SetStatusToNotFound();
return;
}
Debug.Assert(documentMetadata.Etag != null);
if (context.MatchEtag(documentMetadata.Etag.Value))
{
context.SetStatusToNotModified();
return;
}
if (documentMetadata.NonAuthoritiveInformation != null && documentMetadata.NonAuthoritiveInformation.Value)
{
context.SetStatusToNonAuthoritiveInformation();
}
GetDocumentDirectly(context, docId);
});
}
示例3: GetDocumentDirectly
private void GetDocumentDirectly(IHttpContext context, string docId)
{
var doc = Database.Get(docId, GetRequestTransaction(context));
if (doc == null)
{
context.SetStatusToNotFound();
return;
}
if (doc.NonAuthoritiveInformation != null && doc.NonAuthoritiveInformation.Value)
{
context.SetStatusToNonAuthoritiveInformation();
}
Debug.Assert(doc.Etag != null);
doc.Metadata[Constants.LastModified] = doc.LastModified;
context.WriteData(doc.DataAsJson, doc.Metadata, doc.Etag.Value);
}
示例4: Head
private void Head(IHttpContext context, string docId)
{
context.Response.AddHeader("Content-Type", "application/json; charset=utf-8");
var transactionInformation = GetRequestTransaction(context);
var documentMetadata = Database.GetDocumentMetadata(docId, transactionInformation);
if (documentMetadata == null)
{
context.SetStatusToNotFound();
return;
}
Debug.Assert(documentMetadata.Etag != null);
if (context.MatchEtag(documentMetadata.Etag.Value))
{
context.SetStatusToNotModified();
return;
}
if (documentMetadata.NonAuthoritiveInformation != null && documentMetadata.NonAuthoritiveInformation.Value)
{
context.SetStatusToNonAuthoritiveInformation();
}
context.WriteHeaders(documentMetadata.Metadata, documentMetadata.Etag.Value);
}
示例5: GetDocumentDirectly
private void GetDocumentDirectly(IHttpContext context, string docId)
{
var doc = Database.Get(docId, GetRequestTransaction(context));
if (doc == null)
{
context.SetStatusToNotFound();
return;
}
if (doc.NonAuthoritiveInformation)
{
context.SetStatusToNonAuthoritiveInformation();
}
doc.Metadata["Last-Modified"] = doc.LastModified;
context.WriteData(doc.DataAsJson, doc.Metadata, doc.Etag);
}