本文整理汇总了C#中System.Web.HttpResponseBase.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.AddHeader方法的具体用法?C# HttpResponseBase.AddHeader怎么用?C# HttpResponseBase.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.AddHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleResult
public bool HandleResult( IResult result, IFormatInfo outputFormat, HttpRequestBase request, HttpResponseBase response )
{
response.AddHeader("Accept-Ranges", "bytes");
Range range;
if ( !TryGetRequestedRange( request, out range ) )
{
return false;
}
if (!ValidateIfRangeHeader(request, result))
{
return false;
}
var offset = range.Start ?? 0;
var end = range.End.HasValue ? range.End.Value : result.ContentLength - 1;
var length = end - offset + 1;
response.AddHeader( "Content-Range", "bytes " + offset + "-" + end + "/" + result.ContentLength );
response.StatusCode = 206;
result.Serve( response, offset, length );
return true;
}
示例2: GetFile
public static ActionResult GetFile(HttpResponseBase Response, HttpRequestBase Request, HttpServerUtilityBase Server,
string filePath, string fileName, string contentType, string userFileName)
{
byte[] value;
using (FileStream stream = System.IO.File.Open(filePath, FileMode.Open))
{
value = new byte[stream.Length];
stream.Read(value, 0, (int)stream.Length);
}
//const string userFileName = "MissionOrder.pdf";
//const string contentType = "application/pdf";
Response.Clear();
if (Request.Browser.Browser == "IE")
{
string attachment = String.Format("attachment; filename=\"{0}\"", Server.UrlPathEncode(userFileName));
Response.AddHeader("Content-Disposition", attachment);
}
else
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + userFileName + "\"");
Response.ContentType = contentType;
Response.Charset = "utf-8";
Response.HeaderEncoding = Encoding.UTF8;
Response.ContentEncoding = Encoding.UTF8;
Response.BinaryWrite(value);
Response.End();
return null;
}
示例3: OutputExcel
public static void OutputExcel(HttpResponseBase response, string filename, ExcelPackage pck)
{
pck.SaveAs(response.OutputStream);
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AddHeader("content-disposition", "attachment; filename=" + filename + ".xlsx");
response.AddHeader("Content-Length", pck.Stream.Length.ToString());
}
示例4: setGZipCompression_forAjaxRequests
public static void setGZipCompression_forAjaxRequests(HttpRequestBase request, HttpResponseBase response)
{
//based on code from http://geekswithblogs.net/rashid/archive/2007/09/15/Compress-Asp.net-Ajax-Web-Service-Response---Save-Bandwidth.aspx
if (TMConfig.Current.TMSetup.EnableGZipForWebServices.isFalse())
return;
try
{
if (request.ContentType.lower().starts(new List<string> {"text/xml", "application/json"}))
{
string acceptEncoding = request.Headers["Accept-Encoding"];
if (!string.IsNullOrEmpty(acceptEncoding))
{
acceptEncoding = acceptEncoding.ToLower(CultureInfo.InvariantCulture);
if (acceptEncoding.Contains("gzip"))
{
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
response.AddHeader("Content-encoding", "gzip");
}
else if (acceptEncoding.Contains("deflate"))
{
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
response.AddHeader("Content-encoding", "deflate");
}
}
}
}
catch (Exception ex)
{
ex.log("in enableGZipCompression_forAjaxRequests");
}
}
示例5: HandleAjaxRequest
private void HandleAjaxRequest(NotifyEntry entry, HttpResponseBase response)
{
if (entry == null)
return;
response.AddHeader("X-Message-Type", entry.Type.ToString().ToLower());
response.AddHeader("X-Message", entry.Message.Text);
}
示例6: UpdateNoCacheForResponse
public static void UpdateNoCacheForResponse(HttpResponseBase response)
{
response.Buffer = false;
response.BufferOutput = false;
response.AddHeader("Expires", "Fri, 01 Jan 1980 00:00:00 GMT");
response.AddHeader("Pragma", "no-cache");
response.AddHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
}
示例7: CreateFileResponse
private void CreateFileResponse(HttpResponseBase response, AttachmentDO attachment)
{
var fileData = attachment.Bytes;
response.ContentType = "application/octet-stream";
response.AddHeader("Content-Disposition", "filename=\"" + attachment.OriginalName + "\"");
response.AddHeader("Content-Length", fileData.LongLength.ToString());
response.AddHeader("Content-Type", attachment.Type + "; name=\"" + attachment.OriginalName + "\";");
//Write the data
response.BinaryWrite(fileData);
}
示例8: PrepareResponse
protected HttpResponseBase PrepareResponse(HttpResponseBase response)
{
response.ContentType = ContentType;
if (FileName.HasValue())
{
response.AddHeader("Content-Disposition", "attachment; filename=\"{0}\"".FormatCurrent(SanitizeFileName(FileName)));
}
response.AddHeader("Content-Type", ContentType);
return response;
}
示例9: Redirect
private IHttpHandler Redirect(HttpResponseBase response, string url)
{
response.AddHeader("Location", url);
response.StatusCode = 301;
response.End();
return null;
}
示例10: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.AddHeader("content-disposition", $"attachment; filename={FileName}.xlsx");
var generator = _settings.CreateGenerator();
GenerateExcelFile(generator, response.OutputStream);
}
示例11: CopyContents
/// <summary>
/// Copies the full binary contents of the given blob to the given HTTP response.
/// </summary>
private static void CopyContents(CloudBlob blob, HttpResponseBase response, long offset = 0)
{
blob.FetchAttributes();
response.BufferOutput = false;
response.AddHeader("Content-Length", blob.Attributes.Properties.Length.ToString());
response.Flush();
using (var reader = blob.OpenRead())
{
reader.Seek(offset, System.IO.SeekOrigin.Begin);
byte[] buffer = new byte[1024 * 4]; // 4KB buffer
while (reader.CanRead)
{
int numBytes = reader.Read(buffer, 0, buffer.Length);
if (numBytes <= 0)
break;
response.BinaryWrite(buffer);
response.Flush();
}
}
}
示例12: SendMessages
public void SendMessages(HttpResponseBase response, HttpRequestBase request, IEnumerable<Message> messages)
{
if ( !String.IsNullOrEmpty( CometHttpHandler.AllowOrigin ) && request.Headers["Origin"]!=null ) {
if ( CometHttpHandler.IsOriginAllowed( new Uri( request.Headers["Origin"] ) ) ) {
response.AddHeader( "Access-Control-Allow-Origin", request.Headers["Origin"] );
response.AddHeader( "Access-Control-Allow-Methods", "POST, GET, OPTIONS" );
response.AddHeader( "Access-Control-Max-Age", ( 24 * 60 * 60 ).ToString() );
if ( request.Headers["Access-Control-Request-Headers"] != null ) {
response.AddHeader( "Access-Control-Allow-Headers", request.Headers["Access-Control-Request-Headers"] );
}
}
}
response.ContentType = "text/json";
response.Write(MessageConverter.ToJson(messages));
}
示例13: IsFileFromCache
public static bool IsFileFromCache(FileInfo info, HttpRequestBase request, HttpResponseBase response)
{
DateTime updated = info.LastWriteTimeUtc;
string filename = info.Name;
DateTime modifyDate;
if (!DateTime.TryParse(request.Headers["If-Modified-Since"], out modifyDate))
{
modifyDate = DateTime.UtcNow;
}
string eTag = GetFileETag(filename, updated);
if (!IsFileModified(updated, eTag, request))
{
response.StatusCode = (int)System.Net.HttpStatusCode.NotModified;
response.StatusDescription = "Not Modified";
response.AddHeader("Content-Length", "0");
response.Cache.SetCacheability(HttpCacheability.Public);
response.Cache.SetLastModified(updated);
response.Cache.SetETag(eTag);
return true;
}
else
{
response.Cache.SetAllowResponseInBrowserHistory(true);
response.Cache.SetCacheability(HttpCacheability.Public);
response.Cache.SetLastModified(updated);
response.Cache.SetETag(eTag);
return false;
}
}
示例14: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", FileDownloadName));
byte[] fileContents = Convert.FromBase64String(_base64);
response.BinaryWrite(fileContents);
response.End();
}
示例15: FileDownload
public void FileDownload(HttpResponseBase response,string filePah)
{
if(!IsExists(filePah)) {
throw new Exception("�ļ�������");
}
var fileInfo = new FileInfo(filePah);
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name,System.Text.Encoding.UTF8));
response.AddHeader("Content-Length", fileInfo.Length.ToString());
//response.AddHeader("Content-Transfer-Encoding", "binary");
response.ContentType = "application/vnd.ms-excel;charset=UTF-8";
response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
response.WriteFile(fileInfo.FullName);
response.Flush();
response.End();
}