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


C# HttpResponseBase.AddHeader方法代码示例

本文整理汇总了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;
        }
开发者ID:bmbsqd,项目名称:dynamic-media,代码行数:25,代码来源:BytesRangeResultHandler.cs

示例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;
        }
开发者ID:andreyu,项目名称:Reports,代码行数:28,代码来源:GraphicsController.cs

示例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());
 }
开发者ID:honghuamin,项目名称:HanWen,代码行数:7,代码来源:ExcelHelper.cs

示例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");
            }
        }
开发者ID:sempf,项目名称:Dev,代码行数:34,代码来源:GZip.cs

示例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);
        }
开发者ID:GloriousOnion,项目名称:SmartStoreNET,代码行数:8,代码来源:NotifyAttribute.cs

示例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");
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:9,代码来源:GitServerHttpHandler.cs

示例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);
 }
开发者ID:alexed1,项目名称:dtrack,代码行数:11,代码来源:GetAttachment.ashx.cs

示例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;
		}
开发者ID:boatengfrankenstein,项目名称:SmartStoreNET,代码行数:13,代码来源:PdfResult.cs

示例9: Redirect

 private IHttpHandler Redirect(HttpResponseBase response, string url)
 {
     response.AddHeader("Location", url);
     response.StatusCode = 301;
     response.End();
     return null;
 }
开发者ID:revolutionaryarts,项目名称:wewillgather,代码行数:7,代码来源:LegacySitemapHandler.cs

示例10: WriteFile

        protected override void WriteFile(HttpResponseBase response)
        {
            response.AddHeader("content-disposition", $"attachment;  filename={FileName}.xlsx");

            var generator = _settings.CreateGenerator();
            GenerateExcelFile(generator, response.OutputStream);
        }
开发者ID:zihotki,项目名称:LFEG,代码行数:7,代码来源:ExcelFileResultBase.cs

示例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();
                }
            }
        }
开发者ID:robertogg,项目名称:Demos,代码行数:28,代码来源:LogFetcher.cs

示例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));
        }
开发者ID:Wintermoose,项目名称:aspComet,代码行数:16,代码来源:LongPollingTransport.cs

示例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;
     }
 }
开发者ID:rengasamy,项目名称:elFinder.Net,代码行数:29,代码来源:HttpCacheHelper.cs

示例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();
        }
开发者ID:travbod57,项目名称:KendoMVCRampUp,代码行数:8,代码来源:ExcelResult.cs

示例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();
 }
开发者ID:gowhy,项目名称:LoveBank,代码行数:18,代码来源:FileUploadService.cs


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