本文整理汇总了C#中IHttpContext.SetStatusToNotFound方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.SetStatusToNotFound方法的具体用法?C# IHttpContext.SetStatusToNotFound怎么用?C# IHttpContext.SetStatusToNotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.SetStatusToNotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var filename = match.Groups[1].Value;
var etag = context.GetEtag();
switch (context.Request.HttpMethod)
{
case "GET":
Database.TransactionalStorage.Batch(_=> // have to keep the session open for reading of the attachment stream
{
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
using (var stream = attachmentAndHeaders.Data())
{
stream.CopyTo(context.Response.OutputStream);
}
});
break;
case "HEAD":
Database.TransactionalStorage.Batch(_ => // have to keep the session open for reading of the attachment stream
{
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
context.Response.ContentLength64 = attachmentAndHeaders.Size;
});
break;
case "PUT":
var newEtag = Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream,
context.Request.Headers.FilterHeaders(isServerDocument:false));
context.WriteETag(newEtag);
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例2: 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;
}
}
示例3: 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":
Get(context, docId);
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<RavenJObject>().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.AddHeader("Location", Database.Configuration.GetFullUrl("/docs/" + docId));
context.WriteJson(new {Patched = true});
break;
default:
throw new ArgumentOutOfRangeException("Value " + patchResult + " is not understood");
}
break;
}
}
示例4: 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);
});
}
示例5: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
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(isServerDocument:false));
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例6: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
switch (context.Request.HttpMethod)
{
case "HEAD":
if(Database.IndexDefinitionStorage.IndexNames.Contains(index, StringComparer.InvariantCultureIgnoreCase) == false)
context.SetStatusToNotFound();
break;
case "GET":
OnGet(context, index);
break;
case "PUT":
Put(context, index);
break;
case "DELETE":
if(index.StartsWith("Raven/",StringComparison.InvariantCultureIgnoreCase))
{
context.SetStatusToForbidden();
context.WriteJson(new
{
Url = context.Request.RawUrl,
Error = "Builtin indexes cannot be deleted, attempt to delete index '" + index + "' was rejected"
});
return;
}
context.SetStatusToDeleted();
Database.DeleteIndex(index);
break;
}
}
示例7: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
var facetSetupDoc = context.GetFacetSetupDocFromHttpContext();
var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
var jsonDocument = Database.Get(facetSetupDoc, null);
if(jsonDocument == null)
{
context.SetStatusToNotFound();
context.Write("Could not find facet document: " + facetSetupDoc);
return;
}
var etag = GetFacetsEtag(jsonDocument, index);
if(context.MatchEtag(etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteETag(etag);
context.WriteJson(Database.ExecuteGetTermsQuery(index, indexQuery, facetSetupDoc));
}
示例8: Respond
public override void Respond(IHttpContext context)
{
var parameters = GetParametersFromPath(context.GetRequestUrl(), context.Request.QueryString);
var index = Database.IndexStorage.GetIndexInstance(parameters.IndexName);
if (index == null)
{
context.SetStatusToNotFound();
context.WriteJson(new { Error = "The index " + parameters.IndexName + " cannot be found" });
return;
}
var indexEtag = Database.GetIndexEtag(parameters.IndexName, null);
if (context.MatchEtag(indexEtag))
{
context.SetStatusToNotModified();
return;
}
var result = Database.ExecuteMoreLikeThisQuery(parameters, GetRequestTransaction(context), context.GetPageSize(Database.Configuration.MaxPageSize), context.Request.QueryString.GetValues("include"));
if (context.MatchEtag(result.Etag))
{
context.SetStatusToNotModified();
return;
}
context.Response.AddHeader("ETag", result.Etag.ToString());
context.WriteJson(result.Result);
}
示例9: Respond
public override void Respond(IHttpContext context)
{
BoundedMemoryTarget boundedMemoryTarget = null;
if (LogManager.Configuration != null && LogManager.Configuration.AllTargets != null)
{
boundedMemoryTarget = LogManager.Configuration.AllTargets.OfType<BoundedMemoryTarget>().FirstOrDefault();
}
if(boundedMemoryTarget == null)
{
context.SetStatusToNotFound();
context.WriteJson(new
{
Error = "HttpEndpoint was not registered in the log configuration, logs endpoint disable"
});
return;
}
IEnumerable<LogEventInfo> log = boundedMemoryTarget.GeneralLog;
switch (context.Request.QueryString["type"])
{
case "error":
case "warn":
log = boundedMemoryTarget.WarnLog;
break;
}
context.WriteJson(log.Select(x => new
{
x.TimeStamp,
Message = x.FormattedMessage,
x.LoggerName,
Level = x.Level.Name,
Exception = x.Exception == null ? null : x.Exception.ToString()
}));
}
示例10: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
switch (context.Request.HttpMethod)
{
case "HEAD":
if(Database.IndexDefinitionStorage.IndexNames.Contains(index, StringComparer.InvariantCultureIgnoreCase) == false)
context.SetStatusToNotFound();
break;
case "GET":
OnGet(context, index);
break;
case "PUT":
Put(context, index);
break;
case "RESET":
Database.ResetIndex(index);
context.WriteJson(new {Reset = index});
break;
case "DELETE":
context.SetStatusToDeleted();
Database.DeleteIndex(index);
break;
}
}
示例11: RespondToAdmin
public override void RespondToAdmin(IHttpContext context)
{
if (EnsureSystemDatabase(context) == false)
return;
var db = context.Request.QueryString["database"];
if(string.IsNullOrWhiteSpace(db))
{
context.SetStatusToBadRequest();
context.WriteJson(new
{
Error = "Compact request requires a valid database parameter"
});
return;
}
var configuration = server.CreateTenantConfiguration(db);
if (configuration == null)
{
context.SetStatusToNotFound();
context.WriteJson(new
{
Error = "No database named: " + db
});
return;
}
server.LockDatabase(db, () =>
SystemDatabase.TransactionalStorage.Compact(configuration));
}
示例12: Respond
public override void Respond(IHttpContext context)
{
if(notifiedAboutSilverlightBeingRequested == false)
{
lock (this)
{
if (notifiedAboutSilverlightBeingRequested == false &&
SilverlightRequestedAware != null)
SilverlightRequestedAware.SilverlightWasRequested(ResourceStore);
notifiedAboutSilverlightBeingRequested = true;
}
}
var match = urlMatcher.Match(context.GetRequestUrl());
var fileName = match.Groups[1].Value;
var paths = GetPaths(fileName);
var matchingPath = paths.FirstOrDefault(File.Exists);
if (matchingPath != null)
{
context.WriteFile(matchingPath);
return;
}
context.SetStatusToNotFound();
}
示例13: HandleIndexDoesNotExistsException
private static void HandleIndexDoesNotExistsException(IHttpContext ctx, Exception e)
{
ctx.SetStatusToNotFound();
SerializeError(ctx, new
{
Url = ctx.Request.RawUrl,
Error = e.Message
});
}
示例14: TryGetFacets
private bool TryGetFacets(IHttpContext context, string index, out Etag etag, out List<Facet> facets)
{
etag = null;
facets = null;
switch (context.Request.HttpMethod)
{
case "GET":
var facetSetupDoc = context.GetFacetSetupDocFromHttpContext();
if (string.IsNullOrEmpty(facetSetupDoc))
{
var facetsJson = context.Request.QueryString["facets"];
if (string.IsNullOrEmpty(facetsJson) == false)
return TryGetFacetsFromString(context, index, out etag, out facets, facetsJson);
}
JsonDocument jsonDocument = Database.Get(facetSetupDoc, null);
if (jsonDocument == null)
{
context.SetStatusToNotFound();
context.Write("Could not find facet document: " + facetSetupDoc);
return false;
}
etag = GetFacetsEtag(jsonDocument, index);
facets = jsonDocument.DataAsJson.JsonDeserialization<FacetSetup>().Facets;
if (facets == null || !facets.Any())
{
context.SetStatusToNotFound();
context.Write("No facets found in facets setup document:" + facetSetupDoc);
return false;
}
break;
case "POST":
return TryGetFacetsFromString(context, index, out etag, out facets, context.ReadString());
default:
context.SetStatusToBadRequest();
context.Write("No idea how to handle this request");
break;
}
return true;
}
示例15: Respond
public override void Respond(IHttpContext context)
{
var target = LogManager.GetTarget<DatabaseMemoryTarget>();
if(target == null)
{
context.SetStatusToNotFound();
context.WriteJson(new
{
Error = "DatabaseMemoryTarget was not registered in the log manager, logs endpoint disabled"
});
return;
}
var database = Database;
if(database == null)
{
context.SetStatusToBadRequest();
context.WriteJson(new
{
Error = "No database found."
});
return;
}
if(database.Name == null)
{
context.SetStatusToBadRequest();
context.WriteJson(new
{
Error = "Database name is null."
});
return;
}
IEnumerable<LogEventInfo> log = target[Database.Name].GeneralLog;
switch (context.Request.QueryString["type"])
{
case "error":
case "warn":
log = target[Database.Name].WarnLog;
break;
}
context.WriteJson(log.Select(x => new
{
x.TimeStamp,
Message = x.FormattedMessage,
x.LoggerName,
Level = x.Level.ToString(),
Exception = x.Exception == null ? null : x.Exception.ToString()
}));
}