当前位置: 首页>>代码示例>>C#>>正文


C# IHttpContext.WriteHeaders方法代码示例

本文整理汇总了C#中IHttpContext.WriteHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.WriteHeaders方法的具体用法?C# IHttpContext.WriteHeaders怎么用?C# IHttpContext.WriteHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpContext的用法示例。


在下文中一共展示了IHttpContext.WriteHeaders方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
			}
		}
开发者ID:royra,项目名称:ravendb,代码行数:59,代码来源:Static.cs

示例2: Respond

		public override void Respond(IHttpContext context)
		{
			if (EnsureSystemDatabase(context) == false)
				return;

			// This responder is NOT secured, and anyone can access it.
			// Because of that, we need to provide explicit security here.
			
			// Anonymous Access - All / Get / Admin
			// Show all dbs

			// Anonymous Access - None
			// Show only the db that you have access to (read / read-write / admin)

			// If admin, show all dbs

			List<string> approvedDatabases = null;
			var databases = Database.GetDocumentsWithIdStartingWith("Raven/Databases/", null, null, context.GetStart(),
																		context.GetPageSize(Database.Configuration.MaxPageSize),
																		CancellationToken.None);
			var data = databases
				.Select(x => x.Value<RavenJObject>("@metadata").Value<string>("@id").Replace("Raven/Databases/", string.Empty))
				.ToArray();

			if (server.SystemConfiguration.AnonymousUserAccessMode == AnonymousUserAccessMode.None)
			{
				var user = server.RequestAuthorizer.GetUser(context);
				if(user == null)
				{
					return;
				}

				if (user.IsAdministrator(server.SystemConfiguration.AnonymousUserAccessMode) == false)
				{
					approvedDatabases = server.RequestAuthorizer.GetApprovedDatabases(user, context, data);
				}
			}

			Etag lastDocEtag = Etag.Empty;
			Database.TransactionalStorage.Batch(accessor =>
			{
				lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
			});

			if (context.MatchEtag(lastDocEtag))
			{
				context.SetStatusToNotModified();
			}
			else
			{
				context.WriteHeaders(new RavenJObject(), lastDocEtag);

				if(approvedDatabases != null)
				{
					data = data.Where(s => approvedDatabases.Contains(s)).ToArray();
				}

				context.WriteJson(data);
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:60,代码来源:Databases.cs

示例3: Respond

		public override void Respond(IHttpContext context)
		{
			switch (context.Request.HttpMethod)
			{
				case "GET":
					long documentsCount = 0;
					Etag lastDocEtag = Etag.Empty;
					Database.TransactionalStorage.Batch(accessor =>
					{
						lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
						documentsCount = accessor.Documents.GetDocumentsCount();
					});

					lastDocEtag = lastDocEtag.HashWith(BitConverter.GetBytes(documentsCount));
					if (context.MatchEtag(lastDocEtag))
					{
						context.SetStatusToNotModified();
					}
					else
					{
						context.WriteHeaders(new RavenJObject(), lastDocEtag);

						using (var cts = new CancellationTokenSource())
						{
							cts.TimeoutAfter(Settings.DatbaseOperationTimeout);

							var startsWith = context.Request.QueryString["startsWith"];
							if (string.IsNullOrEmpty(startsWith))
								context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString(), cts.Token));
							else
								context.WriteJson(Database.GetDocumentsWithIdStartingWith(
									startsWith,
									context.Request.QueryString["matches"],
									context.Request.QueryString["exclude"],
									context.GetStart(),
									context.GetPageSize(Database.Configuration.MaxPageSize), 
									cts.Token));
						}
					}
					break;
				case "POST":
					var json = context.ReadJson();
					var id = Database.Put(null, Etag.Empty, json,
					                      context.Request.Headers.FilterHeaders(),
					                      GetRequestTransaction(context));
					context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
					context.WriteJson(id);
					break;
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:50,代码来源:Docs.cs

示例4: Respond

		public override void Respond(IHttpContext context)
		{
			switch (context.Request.HttpMethod)
			{
				case "GET":
					long documentsCount = 0;
					Guid lastDocEtag = Guid.Empty;
					Database.TransactionalStorage.Batch(accessor =>
					{
						lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
						documentsCount = accessor.Documents.GetDocumentsCount();
					});

					var array = lastDocEtag.ToByteArray().Concat(BitConverter.GetBytes(documentsCount)).ToArray();
					using (var md5 = MD5.Create())
					{
						var hashed = md5.ComputeHash(array);
						lastDocEtag = new Guid(hashed);
					}

					if (context.MatchEtag(lastDocEtag))
					{
						context.SetStatusToNotModified();
					}
					else
					{
						context.WriteHeaders(new RavenJObject(), lastDocEtag);

						var startsWith = context.Request.QueryString["startsWith"];
						if (string.IsNullOrEmpty(startsWith))
							context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString()));
						else
							context.WriteJson(Database.GetDocumentsWithIdStartingWith(
								startsWith,
								context.Request.QueryString["matches"],
								context.GetStart(),
								context.GetPageSize(Database.Configuration.MaxPageSize)));
					}
					break;
				case "POST":
					var json = context.ReadJson();
					var id = Database.Put(null, Guid.Empty, json,
					                      context.Request.Headers.FilterHeaders(),
					                      GetRequestTransaction(context));
					context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
					context.WriteJson(id);
					break;
			}
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:49,代码来源:Docs.cs

示例5: Respond

		public override void Respond(IHttpContext context)
		{
			switch (context.Request.HttpMethod)
			{
				case "GET":
					Guid lastDocEtag = Guid.Empty;
					Database.TransactionalStorage.Batch(accessor =>
					{
						lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
					});

					if (context.MatchEtag(lastDocEtag))
					{
						context.SetStatusToNotModified();
					}
					else
					{
						context.WriteHeaders(new RavenJObject(), lastDocEtag);

						var startsWith = context.Request.QueryString["startsWith"];
						if (string.IsNullOrEmpty(startsWith))
							context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString()));
						else
							context.WriteJson(Database.GetDocumentsWithIdStartingWith(
								startsWith,
								context.Request.QueryString["matches"],
								context.GetStart(),
								context.GetPageSize(Database.Configuration.MaxPageSize)));
					}
					break;
				case "POST":
					var json = context.ReadJson();
					var id = Database.Put(null, Guid.Empty, json,
										  context.Request.Headers.FilterHeaders(),
										  GetRequestTransaction(context));
					context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
					context.WriteJson(id);
					break;
			}
		}
开发者ID:shiranGinige,项目名称:ravendb,代码行数:40,代码来源:Docs.cs

示例6: Respond

		public override void Respond(IHttpContext context)
		{
			switch (context.Request.HttpMethod)
			{
				case "GET":
					Guid lastDocEtag = Guid.Empty;
					Database.TransactionalStorage.Batch(accessor =>
					{
						lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
					});

					if (context.MatchEtag(lastDocEtag))
					{
						context.SetStatusToNotModified();
					}
					else
					{
						context.WriteHeaders(new RavenJObject(), lastDocEtag);

						context.WriteJson(Database.GetDocumentsWithIdStartingWith("Raven/Databases/", null, context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize)));
					}
					break;
			}
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:24,代码来源:Databases.cs

示例7: 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);
		}
开发者ID:jdaigle,项目名称:ravendb,代码行数:25,代码来源:Document.cs

示例8: 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) && documentMetadata.NonAuthoritativeInformation == false)
			{
				context.SetStatusToNotModified();
				return;
			}

			if (documentMetadata.NonAuthoritativeInformation != null && documentMetadata.NonAuthoritativeInformation.Value)
			{
				context.SetStatusToNonAuthoritativeInformation();
			}
			documentMetadata.Metadata[Constants.LastModified] = documentMetadata.LastModified; //HACK ? to get the document's last modified value into the response headers
			context.WriteHeaders(documentMetadata.Metadata, documentMetadata.Etag.Value);
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:25,代码来源:Document.cs


注:本文中的IHttpContext.WriteHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。