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


C# HttpResponse.WriteAsync方法代码示例

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


在下文中一共展示了HttpResponse.WriteAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteVideoAsync

        protected async Task WriteVideoAsync(HttpResponse response)
        {
            var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
            bufferingFeature?.DisableResponseBuffering();

            var length = FileStream.Length;

            var rangeHeaderValue = response.HttpContext.GetRanges(length);

            var isMultipart = IsMultipartRequest(rangeHeaderValue);

            if (isMultipart)
            {
                response.ContentType = $"multipart/byteranges; boundary={MultipartBoundary}";
            }
            else
            {
                response.ContentType = ContentType.ToString();
            }

            response.Headers.Add("Accept-Ranges", "bytes");

            if (IsRangeRequest(rangeHeaderValue))
            {
                response.StatusCode = (int)HttpStatusCode.PartialContent;

                foreach (var range in rangeHeaderValue.Ranges)
                {
                    if (isMultipart)
                    {
                        await response.WriteAsync($"--{MultipartBoundary}{Environment.NewLine}");
                        await response.WriteAsync($"Content-type: {ContentType}{Environment.NewLine}");
                        await response.WriteAsync($"Content-Range: bytes {range.From}-{range.To}/{length}{Environment.NewLine}");
                    }
                    else
                    {
                        response.Headers.Add("Content-Range", $"bytes {range.From}-{range.To}/{length}");
                    }

                    await WriteDataToResponseBody(response, range);

                    if (isMultipart)
                    {
                        await response.WriteAsync($"{Environment.NewLine}--{MultipartBoundary}--{Environment.NewLine}");
                    }
                }
            }
            else
            {
                await FileStream.CopyToAsync(response.Body);
            }
        }
开发者ID:vtfuture,项目名称:SwiftClient,代码行数:52,代码来源:VideoStreamResult.cs

示例2: DumpConfig

 private static async Task DumpConfig(HttpResponse response, IConfiguration config, string indentation = "")
 {
     foreach (var child in config.GetSubKeys())
     {
         await response.WriteAsync(indentation + "[" + child.Key + "] " + config.Get(child.Key) + "\r\n");
         await DumpConfig(response, child.Value, indentation + "  ");
     }
 }
开发者ID:kulmugdha,项目名称:Entropy,代码行数:8,代码来源:Startup.cs

示例3: WriteOutput

 public static async Task WriteOutput(HttpResponse Response, string Title, string HeadTags, string Body) {
     var sb = new StringBuilder();
     sb.Append("<!DOCTYPE html><head><meta charset=\"utf-8\">");
     if (Title != null) {
         sb.Append("<title>" + Title + "</title>");
     }
     if (HeadTags != null) {
         sb.Append(HeadTags);
     }
     sb.Append("</head><body>");
     sb.Append(Body);
     sb.Append("</body></html>");
     await Response.WriteAsync(sb.ToString());
 }
开发者ID:matthewhancock,项目名称:portsdems,代码行数:14,代码来源:Html.cs

示例4: FilterAsync


//.........这里部分代码省略.........
							FilePath = FilePath,
						});
					}
					catch (FileNotFoundException)
					{
						throw (new HttpException(HttpCode.NOT_FOUND_404));
					}
				}

				if (Cache.Enabled)
				{
					await Console.Out.WriteLineAsync(String.Format("Caching '{0}'", FilePath));
				}

				var FileInfo = await VirtualFileSystem.GetFileInfoAsync(FilePath);

				if (FileInfo.Exists)
				{
					bool ShouldCacheInMemory = FileInfo.Length <= CacheSizeThresold;
					string ETag = null;
					byte[] Data = null;

					if (ShouldCacheInMemory)
					{
						Data = await VirtualFileSystem.ReadAsBytesAsync(FilePath);
						ETag = BitConverter.ToString(MD5.Create().ComputeHash(Data));
					}

					return new ResultStruct()
					{
						RealFilePath = FilePath,
						ContentType = MimeType.GetFromPath(FilePath),
						FileInfo = FileInfo,
						ETag = ETag,
						Data = Data,
						Exists = true,
					};
				}
				else
				{
					throw (new HttpException(HttpCode.NOT_FOUND_404));
				}
			});

			Response.Headers["Content-Type"] = CachedResult.ContentType;
			if (CachedResult.ETag != null)
			{
				Response.Headers["ETag"] = CachedResult.ETag;
			}
			Response.Headers["Date"] = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);
			Response.Headers["Last-Modified"] = CachedResult.FileInfo.LastWriteTimeUtc.ToString("R", CultureInfo.InvariantCulture);
			Response.Headers["Cache-Control"] = "max-age=2419200, private";
			Response.Headers["Expires"] = "Wed, 11 Apr 2022 18:23:41 GMT";

			// Check ETag
			if (Request.Headers["If-None-Match"] != "")
			{
				if (Request.Headers["If-None-Match"] == CachedResult.ETag)
				{
					throw(new HttpException(HttpCode.NOT_MODIFIED_304));
				}
			}

			// Check Last-Modified
			if (Request.Headers["If-Modified-Since"] != "")
			{
				var RequestIfModifiedSince = DateTime.ParseExact(Request.Headers["If-Modified-Since"], "R", CultureInfo.InvariantCulture);

				if (RequestIfModifiedSince == CachedResult.FileInfo.LastWriteTimeUtc)
				{
					throw(new HttpException(HttpCode.NOT_MODIFIED_304));
				}
			}

			Response.Buffering = true;
			Response.ChunkedTransferEncoding = false;

			/*
			Cache-Control:max-age=2419200, private
			Connection:keep-alive
			Date:Wed, 14 Mar 2012 14:52:54 GMT
			Expires:Wed, 11 Apr 2012 14:52:54 GMT
			Last-Modified:Wed, 11 Jan 2012 13:52:46 GMT
			*/

			Response.Headers["Content-Length"] = CachedResult.FileInfo.Length.ToString();

			// Cached byte[]
			if (CachedResult.Data != null)
			{
				await Response.WriteAsync(CachedResult.Data);
			}
			// No cached byte[], stream the file
			else
			{
				Response.Buffering = false;
				//Response.ChunkedTransferEncoding = true;
				await Response.StreamFileASync(CachedResult.RealFilePath);
			}
		}
开发者ID:soywiz,项目名称:NodeNetAsync,代码行数:101,代码来源:HttpStaticFileServer.cs

示例5: WriteContentTypeUnsupported

 private async Task WriteContentTypeUnsupported(HttpResponse response, string contentTypeReturned, Dictionary<string, string> headers)
 {
     response.StatusCode = (int)HttpStatusCode.NotFound;
     await WriteHeaders(response, headers);
     await response.WriteAsync(string.Format("Non-Image content-type returned '{0}'", contentTypeReturned));
 }
开发者ID:maartenba,项目名称:CamoDotNet,代码行数:6,代码来源:CamoServer.cs

示例6: WriteContentLengthExceeded

 private async Task WriteContentLengthExceeded(HttpResponse response, Dictionary<string, string> headers)
 {
     response.StatusCode = (int)HttpStatusCode.NotFound;
     await WriteHeaders(response, headers);
     await response.WriteAsync("Content-Length exceeded");
 }
开发者ID:maartenba,项目名称:CamoDotNet,代码行数:6,代码来源:CamoServer.cs

示例7: WriteInvalidSignature

 private async Task WriteInvalidSignature(HttpResponse response, string url, string signature)
 {
     response.StatusCode = (int)HttpStatusCode.NotFound;
     await response.WriteAsync(string.Format("checksum mismatch {0}:{1}", url, signature));
 }
开发者ID:maartenba,项目名称:CamoDotNet,代码行数:5,代码来源:CamoServer.cs


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