本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例6: SetSourcePersistenceId
public static void SetSourcePersistenceId(this MessagePayload payload, MessagePersistenceId id)
{
Contract.Requires(id != null);
payload.RemoveHeader(typeof(SourcePersistenceHeader));
payload.AddHeader(new SourcePersistenceHeader(id));
}
示例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);
}
示例8: MergeBang
public static void MergeBang(this HttpResponseBase res, Dictionary<string, string> hdrs)
{
foreach (var hdr in hdrs)
{
res.AddHeader(hdr.Key, hdr.Value);
}
}
示例9: AddHeaders
static private void AddHeaders(this HttpWebRequest req, Dictionary<string, string> headers)
{
foreach (var h in headers)
{
req.AddHeader(h.Key, h.Value);
}
}
示例10: ApplyGlobalResponseHeaders
public static void ApplyGlobalResponseHeaders(this IHttpResponse httpRes)
{
foreach (var globalResponseHeader in EndpointHost.Config.GlobalResponseHeaders)
{
httpRes.AddHeader(globalResponseHeader.Key, globalResponseHeader.Value);
}
}
示例11: HtmlResult
public static void HtmlResult(this HttpResponse response, string html)
{
response.Clear();
response.AddHeader("Content-Type", "text/html");
response.Write(html);
response.End();
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}