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


C# this.AddHeader方法代码示例

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


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

示例1: CopyFromAsync

        public static async Task CopyFromAsync(this HttpListenerResponse response, HttpResponseMessage message,
            IContentProcessor contentProcessor)
        {
            response.StatusCode = (int) message.StatusCode;
            foreach (var httpResponseHeader in message.Headers.Where(header => !Filter.Contains(header.Key)))
            {
                foreach (var value in httpResponseHeader.Value)
                {
                    response.AddHeader(httpResponseHeader.Key, value);
                }
            }
            foreach (var httpResponseHeader in message.Content.Headers.Where(header => !Filter.Contains(header.Key)))
            {
                foreach (var value in httpResponseHeader.Value)
                {
                    response.AddHeader(httpResponseHeader.Key, value);
                }
            }
            response.SendChunked = false;
            response.KeepAlive = false;

            var bytes = await message.Content.ReadAsByteArrayAsync();

            if (bytes.Length <= 0) return;

            if (contentProcessor != null)
            {
                bytes = contentProcessor.Process(bytes, message.Content.Headers.ContentType,
                    message.RequestMessage.RequestUri);
            }

            response.ContentLength64 = bytes.Length;
            await response.OutputStream.WriteAsync(bytes, 0, bytes.Length);
        }
开发者ID:Apozhidaev,项目名称:Redirect,代码行数:34,代码来源:HttpListenerResponseExtensions.cs

示例2: BuildBinaryFileResponse

 /// <summary>
 /// Builds a response that will return a binary file to the client.
 /// </summary>
 /// <param name="response">The <see cref="HttpResponse"/> that acts as the this instance.</param>
 /// <param name="fileName">The name of the file.</param>
 /// <param name="fileContents">The file contents.</param>
 /// <param name="encoding">The character encoding of the file. Defaults to <see cref="UTF8Encoding"/>.</param>
 /// <param name="contentType">The Internet Media Type. See <see cref="InternetMediaType"/> for a valid list of values.</param>
 public static void BuildBinaryFileResponse(this HttpResponse response, string fileName, byte[] fileContents, Encoding encoding, string contentType = InternetMediaType.Null)
 {
     response.AddHeader(HttpResponseHeader.ContentDispositionKey, string.Format(HttpResponseHeader.ContentDispositionValueFormat, HttpUtility.UrlPathEncode(fileName)));
     response.AddHeader(HttpResponseHeader.ContentLengthKey, fileContents.Length.ToString());
     response.AddHeader(HttpResponseHeader.PragmaKey, HttpResponseHeader.PragmaValuePublic);
     response.ContentType = contentType;
     response.Charset = encoding.HeaderName;
     response.ContentEncoding = encoding;
     response.BinaryWrite(fileContents);
 }
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:18,代码来源:HttpResponseExtensions.cs

示例3: ReturnCsv

        public static void ReturnCsv(this HttpResponse response, string csvText)
        {
            response.Buffer = true;
            response.Clear();
            response.ClearContent();
            response.ClearHeaders();
            response.ContentType = "text/csv";
            response.AddHeader("content-disposition", "attachment; filename=eway.csv");
            response.AddHeader("Pragma", "public");

            response.Write(csvText);

            response.End();
        }
开发者ID:robgray,项目名称:Tucana,代码行数:14,代码来源:ResponseHelper.cs

示例4: DownloadFile

        public static void DownloadFile(this HttpResponse source, DownloadableFile file)
        {
            var contentData = file.ContentData.IsEmpty()
                                  ? file.ContentText.GetBytes(source.ContentEncoding)
                                  : file.ContentData;

            source.Clear();
            source.Buffer = false;
            source.AddHeader("Accept-Ranges", "bytes");
            source.AddHeader("Content-Disposition", "attachment;filename=\"" + file.FileName + "\"");
            source.AddHeader("Connection", "Keep-Alive");
            source.ContentType = file.ContentType;
            source.BinaryWrite(contentData);
            source.End();
        }
开发者ID:chiganock,项目名称:VtecTeamFlasher,代码行数:15,代码来源:HttpResponseExtensions.cs

示例5: JsonResult

 public static void JsonResult(this HttpResponse response, object data)
 {
     response.Clear();
     response.AddHeader("Content-Type", "application/json");
     response.Write(LogManager.JsonSerializer.SerializeObject(data));
     response.End();
 }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:7,代码来源:Extensions.cs

示例6: SetSourcePersistenceId

        public static void SetSourcePersistenceId(this MessagePayload payload, MessagePersistenceId id)
        {
            Contract.Requires(id != null);

            payload.RemoveHeader(typeof(SourcePersistenceHeader));
            payload.AddHeader(new SourcePersistenceHeader(id));
        }
开发者ID:SystemDot,项目名称:SystemDotServiceBus,代码行数:7,代码来源:MessagePayloadLastPersistenceExtensions.cs

示例7: SetCookie

 /// <summary>
 /// Sets a persistent cookie with an expiresAt date
 /// </summary>
 public static void SetCookie(this IHttpResponse httpRes, string cookieName, 
     string cookieValue, DateTime expiresAt, string path)
 {
     path = path ?? "/";
     var cookie = string.Format("{0}={1};expires={2};path={3}", cookieName, cookieValue, expiresAt.ToString("R"), path);
     httpRes.AddHeader(HttpHeaders.SetCookie, cookie);
 }
开发者ID:nguyennamtien,项目名称:ServiceStack,代码行数:10,代码来源:HttpResponseExtensions.cs

示例8: MergeBang

 public static void MergeBang(this HttpResponseBase res, Dictionary<string, string> hdrs)
 {
     foreach (var hdr in hdrs)
     {
         res.AddHeader(hdr.Key, hdr.Value);
     }
 }
开发者ID:jondot,项目名称:mvc.net-ping,代码行数:7,代码来源:PingResult.cs

示例9: AddHeaders

 static private void AddHeaders(this HttpWebRequest req, Dictionary<string, string> headers)
 {
     foreach (var h in headers)
     {
         req.AddHeader(h.Key, h.Value);
     }
 }
开发者ID:kidozen,项目名称:kido-win,代码行数:7,代码来源:ExtensionsNet.cs

示例10: ApplyGlobalResponseHeaders

 public static void ApplyGlobalResponseHeaders(this IHttpResponse httpRes)
 {
     foreach (var globalResponseHeader in EndpointHost.Config.GlobalResponseHeaders)
     {
         httpRes.AddHeader(globalResponseHeader.Key, globalResponseHeader.Value);
     }
 }
开发者ID:Cyberlane,项目名称:ServiceStack,代码行数:7,代码来源:IHttpResponseExtensions.cs

示例11: HtmlResult

 public static void HtmlResult(this HttpResponse response, string html)
 {
     response.Clear();
     response.AddHeader("Content-Type", "text/html");
     response.Write(html);
     response.End();
 }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:7,代码来源:Extensions.cs

示例12: ForceDownload

 //Forces Download/Save rather than opening in Browser//
 public static void ForceDownload(this HttpResponse Response, string virtualPath, string fileName)
 {
     Response.Clear();
     Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
     Response.WriteFile(virtualPath);
     Response.ContentType = "";
     Response.End();
 }
开发者ID:riguelbf,项目名称:portalSureg,代码行数:9,代码来源:HttpExtensions.ashx.cs

示例13: SendAttachment

 /// <summary>
 ///     A HttpResponse extension method that sends an attachment.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="fullPathToFile">The full path to file.</param>
 /// <param name="outputFileName">Filename of the output file.</param>
 public static void SendAttachment(this HttpResponse @this, string fullPathToFile, string outputFileName)
 {
     @this.Clear();
     @this.AddHeader("content-disposition", "attachment; filename=" + outputFileName);
     @this.WriteFile(fullPathToFile);
     @this.ContentType = "";
     @this.End();
 }
开发者ID:fqybzhangji,项目名称:Z.ExtensionMethods,代码行数:14,代码来源:HttpResponse.SendAttachment.cs

示例14: AddHeaders

 public static IMessageBuilder AddHeaders(this IMessageBuilder messageBuilder, IEnumerable<IMessageHeaderWithMustUnderstandSpecification> headers)
 {
     foreach (var header in headers)
     {
         messageBuilder.AddHeader(header.Header, header.MustUnderstand);
     }
     return messageBuilder;
 }
开发者ID:SzymonPobiega,项目名称:WS-Man.Net,代码行数:8,代码来源:MessageBuilderExtensions.cs

示例15: AddTogglAuth

        public static void AddTogglAuth(this IRestRequest req, TogglAuthRequest auth)
        {
            string encodedAuthString = String.IsNullOrWhiteSpace(auth.ApiToken) ?
                Convert.ToBase64String(Encoding.UTF8.GetBytes(auth.UserName + ":" + auth.Password)) :
                Convert.ToBase64String(Encoding.UTF8.GetBytes(auth.ApiToken + ":api_token"));

            req.AddHeader("Authorization", "Basic " + encodedAuthString);
        }
开发者ID:RC7502,项目名称:togglnetapi,代码行数:8,代码来源:Extensions.cs


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