本文整理汇总了C#中System.Web.HttpResponseBase.AppendHeader方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.AppendHeader方法的具体用法?C# HttpResponseBase.AppendHeader怎么用?C# HttpResponseBase.AppendHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.AppendHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChooseSuitableCompression
public static void ChooseSuitableCompression(NameValueCollection requestHeaders, HttpResponseBase response)
{
if (requestHeaders == null) throw new ArgumentNullException(nameof(requestHeaders));
if (response == null) throw new ArgumentNullException(nameof(response));
/// load encodings from header
QValueList encodings = new QValueList(requestHeaders[ACCEPT_ENCODING_HEADER]);
/// get the types we can handle, can be accepted and
/// in the defined client preference
QValue preferred = encodings.FindPreferred("gzip", "deflate", "identity");
/// if none of the preferred values were found, but the
/// client can accept wildcard encodings, we'll default
/// to Gzip.
if (preferred.IsEmpty && encodings.AcceptWildcard && encodings.Find("gzip").IsEmpty)
preferred = new QValue("gzip");
// handle the preferred encoding
switch (preferred.Name)
{
case "gzip":
response.AppendHeader(CONTENT_ENCODING_HEADER, "gzip");
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
break;
case "deflate":
response.AppendHeader(CONTENT_ENCODING_HEADER, "deflate");
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
break;
case "identity":
default:
break;
}
}
示例2: AddResponseHeaders
// Adds the website's standard do-not-cache response headers to the specified HTTP response.
// Called by this class, and can also be called from outside (see the CsvActionResult).
// These particular headers should not be added for file-save responses, when the browser is
// (certain versions of) IE, because they would stop IE from saving the file.
public static void AddResponseHeaders(HttpResponseBase response)
{
if (response != null)
{
response.AppendHeader("Cache-Control", "no-cache, no-store, max-age=0");
response.AppendHeader("Pragma", "no-cache, no-store");
response.AppendHeader("Vary", "*");
}
}
示例3: Compress
/// <summary>
/// Compress the response.
/// </summary>
/// <param name="acceptEncoding">The type of accepted compression.</param>
/// <param name="response">The actions response.</param>
private static void Compress(string acceptEncoding, HttpResponseBase response)
{
Guard.NotNullOrEmpty(() => acceptEncoding);
Guard.NotNull(() => response);
if (acceptEncoding.Contains("GZIP"))
{
response.AppendHeader("Content-encoding", "gzip");
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
}
else if (acceptEncoding.Contains("DEFLATE"))
{
response.AppendHeader("Content-encoding", "deflate");
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
}
}
示例4: EncodeStreamAndAppendResponseHeaders
public static void EncodeStreamAndAppendResponseHeaders(HttpResponseBase response, string acceptEncoding)
{
if (acceptEncoding == null) return;
var preferredEncoding = ParsePreferredEncoding(acceptEncoding);
if (preferredEncoding == null) return;
response.AppendHeader("Content-Encoding", preferredEncoding);
response.AppendHeader("Vary", "Accept-Encoding");
if (preferredEncoding == "deflate")
{
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress, true);
}
if (preferredEncoding == "gzip")
{
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress, true);
}
}
示例5: Export
/// <summary>
/// Exports the specified response.
/// </summary>
/// <param name="response">The response.</param>
/// <param name="myPageName">Name of my page.</param>
/// <param name="columns">The columns.</param>
/// <param name="ds">The ds.</param>
/// <Remarks>
/// Created Time: 2008-8-4 10:59
/// Created By: jack_que
/// Last Modified Time:
/// Last Modified By:
/// </Remarks>
public static void Export(HttpResponseBase response, string myPageName, List<MESParameterInfo> columns, DataSet ds)
{
string path = AppDomain.CurrentDomain.BaseDirectory + @"\Excel\" + myPageName + ".xls";
response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=" + myPageName + ".xls");
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.ContentType = "application/ms-excel";
ExcelWriter excel = new ExcelWriter(path);
try
{
excel.BeginWrite();
short row = 0;
for (short k = 0; k < columns.Count; k++)
{
excel.WriteString(row, k, columns[k].ParamDisplayName);
}
DataTable dt = ds.Tables[0];
for (short i = 0; i < dt.Rows.Count; i++)
{
row++;
for (short j = 0; j < columns.Count; j++)
{
MESParameterInfo column = columns[j];
string columnType = column.ParamType;
string columnName = column.ParamName;
object value = ds.Tables[0].Rows[i][columnName];
if (columnType != null && columnType.Equals("date"))
{
value = value.ToString().Split(new char[] { ' ' }, StringSplitOptions.None)[0];
}
excel.WriteString(row, j, value.ToString());
}
}
}
finally
{
excel.EndWrite();
}
FileInfo file = new FileInfo(path);
if (file.Exists)
{
response.WriteFile(path);
response.Flush();
file.Delete();
}
}
示例6: WriteExcelFile
public static void WriteExcelFile(HttpResponseBase response,string output,string fileName)
{
response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.ContentType = "application/ms-excel";
response.Write(output);
}
示例7: AppendHeader
/// <summary>
/// Append header to response
/// </summary>
/// <remarks>
/// Seems like appendheader only works with IIS 7
/// </remarks>
/// <param name="response"></param>
/// <param name="httpResponseHeader"></param>
/// <param name="headerValue"></param>
public void AppendHeader(HttpResponseBase response, string httpResponseHeader, string headerValue)
{
switch (WebServerType)
{
case WebServerType.IIS7:
response.AppendHeader(httpResponseHeader, headerValue);
break;
default:
response.AddHeader(httpResponseHeader, headerValue);
break;
}
}
示例8: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.Clear();
if(!string.IsNullOrEmpty(Etag))
{
response.AppendHeader("ETag", Etag);
}
response.ContentType = "image/png";
var renderer = new IdenticonRenderer();
using(Bitmap b = renderer.Render(Code, Size))
{
using(var stream = new MemoryStream())
{
b.Save(stream, ImageFormat.Png);
stream.WriteTo(response.OutputStream);
}
}
}
示例9: PackageResponse
/// <summary>
/// Packages the response. <c>Flush()</c> would be called in this method.
/// </summary>
/// <param name="response">The response.</param>
/// <param name="data">The data.</param>
/// <param name="ex">The ex.</param>
/// <param name="acceptEncoding">The accept encoding.</param>
/// <param name="noBody">if set to <c>true</c> [no body].</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="settings">The settings.</param>
public static void PackageResponse(HttpResponseBase response, object data, BaseException ex = null, string acceptEncoding = null, bool noBody = false, string contentType = null, RestApiSettings settings = null)
{
if (response != null)
{
if (settings == null)
{
settings = defaultRestApiSettings;
}
var objectToReturn = ex != null ? (settings.OmitExceptionDetail ? ex.ToSimpleExceptionInfo() : ex.ToExceptionInfo()) : data;
response.Headers.Add(HttpConstants.HttpHeader.SERVERNAME, EnvironmentCore.ServerName);
response.Headers.AddIfNotNullOrEmpty(HttpConstants.HttpHeader.TRACEID, ApiTraceContext.TraceId);
response.StatusCode = (int)(ex == null ? (noBody ? HttpStatusCode.NoContent : HttpStatusCode.OK) : ex.Code.ToHttpStatusCode());
if (!noBody)
{
response.ContentType = contentType.SafeToString(HttpConstants.ContentType.Json);
if (settings.EnableContentCompression)
{
acceptEncoding = acceptEncoding.SafeToString().ToLower();
if (acceptEncoding.Contains(HttpConstants.HttpValues.GZip))
{
response.Filter = new System.IO.Compression.GZipStream(response.Filter,
System.IO.Compression.CompressionMode.Compress);
response.Headers.Remove(HttpConstants.HttpHeader.ContentEncoding);
response.AppendHeader(HttpConstants.HttpHeader.ContentEncoding, HttpConstants.HttpValues.GZip);
}
else if (acceptEncoding.Contains("deflate"))
{
response.Filter = new System.IO.Compression.DeflateStream(response.Filter,
System.IO.Compression.CompressionMode.Compress);
response.Headers.Remove(HttpConstants.HttpHeader.ContentEncoding);
response.AppendHeader(HttpConstants.HttpHeader.ContentEncoding, "deflate");
}
}
response.Write(objectToReturn.ToJson(true, JsonConverters));
}
response.Headers.Add(HttpConstants.HttpHeader.SERVEREXITTIME, DateTime.UtcNow.ToFullDateTimeTzString());
}
}
示例10: ApplyClientCachePolicy
/// <summary>
/// 应用客户端缓存策略
/// </summary>
public void ApplyClientCachePolicy( HttpResponseBase response )
{
string cacheControl;
switch ( _cacheability )
{
case HttpCacheability.NoCache:
cacheControl = "no-cache";
break;
case HttpCacheability.Public:
cacheControl = "public";
break;
default:
case HttpCacheability.Private:
cacheControl = "private";
break;
}
if ( cacheControl != "no-cache" )
{
if ( _maxAge != null )
cacheControl += ",max-age=" + (int) _maxAge.Value.TotalSeconds;
if ( _sMaxAge != null )
cacheControl += ",s-maxage=" + (int) _sMaxAge.Value.TotalSeconds;
}
response.AppendHeader( "Cache-Control", cacheControl );
if ( _expires != null )
response.AppendHeader( "Expires", _expires.Value.ToString( "R" ) );
if ( _lastModified != null )
response.AppendHeader( "Last-Modified", _lastModified.Value.ToString( "R" ) );
if ( _etag != null )
response.AppendHeader( "ETag", _etag );
if ( _varyHeaders != null && _varyHeaders.Any() )
response.AppendHeader( "Vary", string.Join( ",", _varyHeaders ) );
}
示例11: AddFormValuesToCookie
private void AddFormValuesToCookie(HttpResponseBase response, NameValueCollection formValues)
{
if(formValues == null || formValues.Count == 0)
return;
// Add form values to the cookie in batches of 20.
//var cookieIndex = 0;
var cookie = new HttpCookie("prelogin-form-params");
cookie.Values.Add("dest_url", HttpUtility.UrlEncode(FilterContext.HttpContext.Request.Url.ToString()));
foreach (var key in formValues.AllKeys)
cookie.Values.Add(key, HttpUtility.UrlEncode(formValues[key]));
response.Cookies.Add(cookie);
response.AppendHeader("P3P", "CP=\"CAO PSA OUR\"");
}
示例12: ExportToExcelWithOutHeader
/// <summary>
/// Exports to excel with out header.
/// </summary>
/// <param name="response">The response.</param>
/// <param name="myPageName">Name of my page.</param>
/// <param name="ds">The ds.</param>
/// <Remarks>
/// Created Time: 08-12-24 14:20
/// Created By: jack_que
/// Last Modified Time:
/// Last Modified By:
/// </Remarks>
public static void ExportToExcelWithOutHeader(HttpResponseBase response, string myPageName, DataSet ds)
{
response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=Sheet1.xls" );
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.ContentType = "application/ms-excel";
//response.ContentType = "text/csv";
StringBuilder builder = new StringBuilder();
builder.Append("<html><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
.Append("<body><table width='100%' border='1'><tr bgcolor='gray' style='COLOR: white'>");
foreach (DataColumn column in ds.Tables[0].Columns)
{
builder.Append("<td align='center'>").Append(column.ColumnName.ToLower()).Append("</td>");
}
builder.Append("</tr>");
foreach (DataRow row in ds.Tables[0].Rows)
{
builder.Append("<tr>");
foreach (DataColumn column in ds.Tables[0].Columns)
{
builder.Append("<td>").Append(row[column].ToString()).Append("</td>");
}
builder.Append("</tr>");
}
builder.Append("</table></body></html>");
response.Output.Write(builder.ToString());
}
示例13: ExportToExcel
/// <summary>
/// Exports to excel.
/// </summary>
/// <param name="response">The response.</param>
/// <param name="myPageName">Name of my page.</param>
/// <param name="columns">The columns.</param>
/// <param name="list">The list.</param>
/// <Remarks>
/// Created Time: 2008-7-8 15:40
/// Created By: jack_que
/// Last Modified Time:
/// Last Modified By:
/// </Remarks>
public static void ExportToExcel(HttpResponseBase response, string myPageName, List<MESParameterInfo> columns,List<Dictionary<string,string>> list)
{
string FileName = myPageName + ".xls";
response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
string ss = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.ContentType = "application/ms-excel";
StringBuilder builder = new StringBuilder();
builder.Append("<html><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
.Append("<body><table width='100%' border='1'><tr bgcolor='gray' style='COLOR: white'>");
for (int k = 0; k < columns.Count; k++)
{
builder.Append("<td align='center'>").Append(columns[k].ParamDisplayName).Append("</td>");
}
builder.Append("</tr>");
for (int i = 0; i < list.Count; i++)
{
Dictionary<string, string> dic = list[i];
builder.Append("<tr>");
for (int j = 0; j < columns.Count; j++)
{
MESParameterInfo column = columns[j];
string columnType = column.ParamType;
string columnName = column.ParamName;
string value = dic[columnName];
if (columnType != null && columnType.Equals("date"))
{
value = value.Split(new char[] { ' ' }, StringSplitOptions.None)[0];
}
builder.Append("<td>").Append(value.ToString()).Append("</td>");
}
builder.Append("</tr>");
}
builder.Append("</table></body></html>");
response.Output.Write(builder.ToString());
}
示例14: SetEncoding
private static void SetEncoding(HttpResponseBase httpResponse, string encoding)
{
httpResponse.AppendHeader(_contentEncoding, encoding);
httpResponse.Cache.VaryByHeaders[_acceptEncoding] = true;
}
示例15: Apply
/// <summary>
/// 将响应直接输出
/// </summary>
/// <param name="response">HttpResponse 对象,用于输出响应</param>
public virtual void Apply( HttpResponseBase response )
{
response.Clear();
response.HeaderEncoding = HeaderEncoding;
foreach ( var key in Headers.AllKeys )
{
foreach ( var value in Headers.GetValues( key ) )
{
response.AppendHeader( key, value );
}
}
response.ContentEncoding = ContentEncoding;
response.Write( Content );
}