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


C# HttpResponse.End方法代码示例

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


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

示例1: WriteJsonData

    //truyen json data len form
    public static void WriteJsonData(HttpResponse response, Object obj)
    {
        response.Clear();
        response.ClearContent();
        response.ClearHeaders();
        System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue, RecursionLimit = 100 };

        string output = oSerializer.Serialize(obj);

        response.ContentType = "Application/Json";
        response.Write(output);
        response.End();
    }
开发者ID:Vinhbaba,项目名称:dskfeorfqlhvsea,代码行数:14,代码来源:Default.aspx.cs

示例2: ExportCSV

    protected static void ExportCSV(HttpResponse response, string fileText, string fileName)
    {
        byte[] buffer = GetBytes(fileText);

        try
        {
            response.Clear();
            response.ContentType = "text/plain";
            response.OutputStream.Write(buffer, 0, buffer.Length);
            response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
            response.End();
        }
        catch (System.Web.HttpException ex)
        {
            // ignore exception where user closed the download box
            if (!ex.Message.StartsWith("The remote host closed the connection. The error code is"))
                throw;
        }
    }
开发者ID:nblaurenciana-md,项目名称:Websites,代码行数:19,代码来源:CallCenterV2.aspx.cs

示例3: sendFile

 private void sendFile(HttpResponse response, string fileName)
 {
     /*
      * client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println("Connection: close");  // the connection will be closed after completion of the response
         client.println();
      */
     response.Clear();
     response.BufferOutput = true;
     response.StatusCode = 200; // HttpStatusCode.OK;
     response.Write(SD.readAllFile(fileName));
     response.ContentType = "text/html";
     response.End();
 }
开发者ID:kum63304,项目名称:SmartHouse,代码行数:15,代码来源:ArduinoHttpHandler.cs

示例4: ProcessImage

    private void ProcessImage(HttpApplication app, HttpResponse Response, HttpRequest Request)
    {
        string file = Request.Path.Substring(4).ToLower(); // stripping out the /cms part ...

        string output = "";

        Response.Clear();
        Response.ContentType = GetContentTypeOfFile(file);

        int newWidth = 0;
        int newHeight = 0;
        int maxWidth = 0;
        int maxHeight = 0;

        if (Request["w"] != null)
            newWidth = Convert.ToInt32(Request["w"].ToString());
        if (Request["h"] != null)
            newHeight = Convert.ToInt32(Request["h"].ToString());
        if (Request["mw"] != null)
            maxWidth = Convert.ToInt32(Request["mw"].ToString());
        if (Request["mh"] != null)
            maxHeight = Convert.ToInt32(Request["mh"].ToString());

        try
        {

            if (newWidth > 0 || newHeight > 0 || maxHeight > 0 || maxWidth > 0)
            {

                // resize and render the image

                // should cache it and reuse when possibl...

                Image i = Image.FromFile(Request.MapPath(Request.Path));

                using (MemoryStream ms = new MemoryStream())
                {

                    int newWidth2 = newWidth;
                    int newHeight2 = newHeight;

                    if (newWidth > 0 && newHeight == 0)
                        newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth);
                    else if (newHeight > 0 && newWidth == 0)
                        newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight);

                    if (newHeight2 == 0) newHeight2 = i.Height;
                    if (newWidth2 == 0) newWidth2 = i.Width;

                    if (maxWidth > 0 && newWidth2 > maxWidth)
                    {
                        newWidth2 = maxWidth;
                        newHeight2 = Convert.ToInt32(((double)i.Height / (double)i.Width) * (double)newWidth2);
                    }
                    if (maxHeight > 0 && newHeight2 > maxHeight)
                    {
                        newHeight2 = maxHeight;
                        newWidth2 = Convert.ToInt32(((double)i.Width / (double)i.Height) * (double)newHeight2);
                    }

                    Bitmap i2 = new Bitmap(i, newWidth2, newHeight2);

                    i2.Save(ms, GetImageFormatOfFile(file));

                    Response.BinaryWrite(ms.ToArray());
                }

            }
            else
            {
                // is there a way to call default handler instead of this??
                Response.WriteFile(Request.MapPath(Request.Path));
            }
        }
        catch
        {
            Response.WriteFile(Request.MapPath(Request.Path));
        }

        Response.End();
    }
开发者ID:ronmichael,项目名称:img2,代码行数:81,代码来源:ImgHandler.cs

示例5: DownloadDocument

    public static void DownloadDocument(HttpResponse httpResponse, byte[] fileContents, string fileName)
    {
        try
        {

            string contentType = "application/octet-stream";
            try { contentType = Utilities.GetMimeType(System.IO.Path.GetExtension(fileName)); }
            catch (Exception) { }

            httpResponse.Clear();
            httpResponse.ClearHeaders();

            // add cooke so that javascript can detect when file downloaded is done and started if it want's to
            // do something (such as letter print page to deselect leter to print)
            httpResponse.Cookies["fileDownloaded"].Value = "true";
            httpResponse.Cookies["fileDownloaded"].Expires = DateTime.Now.AddHours(3);

            httpResponse.ContentType = contentType;
            httpResponse.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
            httpResponse.OutputStream.Write(fileContents, 0, fileContents.Length);
            httpResponse.Flush();
            httpResponse.End();
        }
        catch (System.Web.HttpException ex)
        {
            // ignore exception where user closed the download box
            if (!ex.Message.StartsWith("The remote host closed the connection. The error code is"))
                throw;
        }
    }
开发者ID:mcep,项目名称:Mediclinic,代码行数:30,代码来源:Letter.cs

示例6: ExportExcel

    /// <summary>
    /// Export excel with binary format using ClosedXml library 
    /// </summary>
    /// <param name="response">Current page response</param>
    /// <param name="dt">DataTabe</param>
    /// <param name="columnWidths">double array to define the with of column</param>
    public static void ExportExcel(HttpResponse response, string fileName, DataTable dt, double[] columnWidths)
    {
        try
        {
            int numColumn = columnWidths.Length;
            using (XLWorkbook wb = new XLWorkbook())
            {
                var ws = wb.Worksheets.Add(dt);

                using (MemoryStream MyMemoryStream = new MemoryStream())
                {
                    ws.Tables.First().ShowAutoFilter = false;
                    ws.Tables.First().ShowRowStripes = false;
                    ws.Tables.First().Theme = XLTableTheme.None;

                    ws.SheetView.FreezeRows(1);

                    ws.Row(1).Style.Font.FontColor = XLColor.Black;
                    ws.Row(1).Style.Font.Bold = true;
                    ws.Row(1).Style.Alignment.Indent = 1;
                    ws.Range(1, 1, 1, numColumn).Style.Fill.BackgroundColor = XLColor.LightGreen;

                    ws.Column(1).Width = columnWidths[0];
                    if (columnWidths.Length == 18)
                    {
                        ws.Column(1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                    }
                    ws.Column(1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;

                    for (int i = 1; i < numColumn; i++)
                    {
                        ws.Column(i + 1).Width = columnWidths[i];
                        ws.Column(i + 1).Style.Alignment.WrapText = true;
                        ws.Column(i + 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
                    }

                    ws.RangeUsed().Style.Border.InsideBorderColor = XLColor.Black;
                    ws.RangeUsed().Style.Border.OutsideBorderColor = XLColor.Black;
                    ws.RangeUsed().Style.Border.InsideBorder = XLBorderStyleValues.Thin;
                    ws.RangeUsed().Style.Border.OutsideBorder = XLBorderStyleValues.Thin;

                    wb.SaveAs(MyMemoryStream);

                    response.Clear();
                    response.Buffer = true;
                    response.Charset = "";
                    response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
                    MyMemoryStream.WriteTo(response.OutputStream);
                    response.Flush();
                    response.End();
                }
            }
        }
        catch (Exception ex)
        {
            Pollinator.Common.Logger.Error("Error occured at " + typeof(ImportExportUltility).Name + " ExportExcel().:", ex);
            response.End();
        }
    }
开发者ID:nazrulcse,项目名称:pollinatror,代码行数:66,代码来源:ImportExportUltility.cs

示例7: Write


//.........这里部分代码省略.........
				{
					double ratio = _appState.Extent.Width * 96 / _originalWidth;
          dx = mapElement.Width * ratio * 0.5;
          dy = mapElement.Height * ratio * 0.5;
				}
				else
				{
					dx = _appState.Extent.Width * 0.5;
          dy = dx * mapElement.Height / mapElement.Width;
				}

        _appState.Extent = new Envelope(new Coordinate(c.Coordinate.X - dx, c.Coordinate.Y - dy), new Coordinate(c.Coordinate.X + dx, c.Coordinate.Y + dy));
			}

      double conversion = AppSettings.MapUnits == "feet" ? 1 : Constants.FeetPerMeter;
      mapScale = _appState.Extent.Width * conversion / mapElement.Width;

      _pixelSize = _appState.Extent.Width / (mapElement.Width * PixelsPerInch);
		}

    int inputIndex = 0;

		// get the page template elements and draw each one to the page

		foreach (Configuration.PrintTemplateContentRow element in printTemplate.GetPrintTemplateContentRows())
		{
      switch (element.ContentType)
			{
				case "box":
          CreatePdfBox(content, element);
					break;

				case "date":
          CreatePdfText(content, element, DateTime.Now.ToString("MMMM d, yyyy"));
					break;

				case "image":
          CreatePdfImage(content, element);
					break;

				case "legend":
          CreatePdfLegend(content, element);
					break;

				case "map":
          CreatePdfMap(content, element);
					break;

        case "overviewmap":
          CreatePdfOverviewMap(content, element);
          break;

				case "scale":
					if (mapScale > 0)
					{
            CreatePdfText(content, element, "1\" = " + mapScale.ToString("0") + " ft");
					}
					break;

        case "scalefeet":
          if (mapScale > 0)
          {
            CreatePdfText(content, element, mapScale.ToString("0") + " ft");
          }
          break;

        case "tabdata":
          CreatePdfTabData(content, element);
          break;

				case "text":
          if (!element.IsTextNull())
					{
            CreatePdfText(content, element, element.Text);
					}
          else if (!element.IsFileNameNull())
          {
            string fileName = HttpContext.Current.Server.MapPath("Text/Print") + "\\" + element.FileName;

            if (File.Exists(fileName))
            {
              string text = File.ReadAllText(fileName);
              CreatePdfText(content, element, text);
            }
          }
					break;

				case "input":
					if (inputIndex < _input.Count)
					{
            CreatePdfText(content, element, _input[inputIndex]);
            ++inputIndex;
					}
					break;
			}
		}

		document.Close();
		response.End();
	}
开发者ID:ClaireBrill,项目名称:GPV,代码行数:101,代码来源:PdfMap.cs

示例8: ExportToCSV

 private void ExportToCSV(string exportContent, HttpResponse response)
 {
     response.Clear();
     response.AddHeader("content-disposition", "attachment;filename=" + fileName);
     response.Charset = "";
     response.ContentType = "application/octet-stream";
     System.IO.StringWriter stringWrite = new System.IO.StringWriter();
     System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
     response.Write(exportContent);
     response.End();
 }
开发者ID:raselahmmedgit,项目名称:simreg-sample,代码行数:11,代码来源:ExcelManager.cs

示例9: ProcessRequest


//.........这里部分代码省略.........
    {
      Response.Clear();

      List<String> placemarks = new List<String>();
      Dictionary<String, String> styles = new Dictionary<String, String>();
      string appName = null;
      string groupName = null;

      using (OleDbConnection connection = AppContext.GetDatabaseConnection())
      {
        string sql = String.Format("update {0}MarkupGroup set DateLastAccessed = ? where GroupID = ?", AppSettings.ConfigurationTablePrefix);

        using (OleDbCommand command = new OleDbCommand(sql, connection))
        {
          command.Parameters.Add("@1", OleDbType.Date).Value = DateTime.Now;
          command.Parameters.Add("@2", OleDbType.Integer).Value = groupId;
          command.ExecuteNonQuery();

          command.CommandText = String.Format("select Shape, Color, Text from {0}Markup where GroupID = ? and Deleted = 0", AppSettings.ConfigurationTablePrefix);
          command.Parameters.Clear();
          command.Parameters.Add("@1", OleDbType.Integer).Value = groupId;

          WKTReader wktReader = new WKTReader();

          using (OleDbDataReader reader = command.ExecuteReader())
          {
            while (reader.Read())
            {
              IGeometry geometry = wktReader.Read(reader.GetString(0));
              string coordinates = GetCoordinates(geometry);
              string color = reader.GetString(1);
              bool isText = !reader.IsDBNull(2);

              string styleId = GetStyle(geometry.OgcGeometryType, color, isText, styles);

              switch (geometry.OgcGeometryType)
              {
                case OgcGeometryType.Point:
                  string name = isText ? String.Format("<name>{0}</name>", reader.GetString(2)) : "";
                  placemarks.Add(String.Format("<Placemark>{0}<styleUrl>#{1}</styleUrl><Point>{2}</Point></Placemark>", name, styleId, coordinates));
                  break;

                case OgcGeometryType.LineString:
                  placemarks.Add(String.Format("<Placemark><styleUrl>#{0}</styleUrl><LineString>{1}</LineString></Placemark>", styleId, coordinates));
                  break;

                case OgcGeometryType.Polygon:
                  placemarks.Add(String.Format("<Placemark><styleUrl>#{0}</styleUrl><Polygon><outerBoundaryIs><LinearRing>{1}</LinearRing></outerBoundaryIs></Polygon></Placemark>", styleId, coordinates));
                  break;
              }
            }
          }

          Configuration config = AppContext.GetConfiguration();
          Configuration.ApplicationRow application = config.Application.Select(String.Format("ApplicationID = '{0}'", appId))[0] as Configuration.ApplicationRow;
          appName = application.DisplayName;

          command.CommandText = String.Format("select DisplayName from {0}MarkupGroup where GroupID = ?", AppSettings.ConfigurationTablePrefix);
          groupName = command.ExecuteScalar() as string;
        }
      }

      string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmssff");
      string kmzName = String.Format("Markup_{0}.kmz", timeStamp);
      string kmlName = String.Format("Markup_{0}.kml", timeStamp);

      string kml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
          <kml xmlns=""http://earth.google.com/kml/2.2"">
            <Folder>
              <name>{0}</name>
              <Document>
                <name>Markup: {1}</name>
                {2}
                {3}
              </Document>
            </Folder>
          </kml>";

      string[] styleArray = new string[styles.Values.Count];
      styles.Values.CopyTo(styleArray, 0);

      kml = String.Format(kml, appName, groupName, String.Join("", styleArray), String.Join("", placemarks.ToArray()));

      Response.ContentType = "application/vnd.google-earth.kmz";
      Response.AddHeader("Content-Disposition", "attachment; filename=" + kmzName);

      ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream);

      MemoryStream memoryStream = new MemoryStream();
      byte[] buffer = (new UTF8Encoding()).GetBytes(kml);

      ZipEntry entry = new ZipEntry(kmlName);
      entry.Size = buffer.Length;
      zipStream.PutNextEntry(entry);
      zipStream.Write(buffer, 0, buffer.Length);

      zipStream.Finish();
      Response.End();
    }
  }
开发者ID:ClaireBrill,项目名称:GPV,代码行数:101,代码来源:ExportMarkupHandler.cs

示例10: ExportToExcel

    public static void ExportToExcel(HttpResponse response, DataSet ds)
    {
        NumberFormatInfo numInfo = Util.GetYankeeNumberFormat();
        DataTable dt = ds.Tables[0];

        response.ClearContent();
        response.ContentEncoding = System.Text.Encoding.UTF8;
        response.ContentType = "application/vnd.ms-excel";
        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        response.Write("\n");
        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                switch (Util.GetMainTypeCode(dr[i].GetType()))
                {
                    case MainTypeCodes.Number:
                        response.Write(tab + ((decimal)dr[i]).ToString("0.00#####", numInfo));
                        break;
                    case MainTypeCodes.DateTime:
                        response.Write(tab + ((DateTime)dr[i]).ToString("yyyy-MM-dd"));
                        break;
                    default:
                        response.Write(tab + dr[i].ToString());
                        break;
                }
                tab = "\t";
            }
            response.Write("\n");
        }
        response.End();
    }
开发者ID:kiquenet,项目名称:B4F,代码行数:39,代码来源:Utility.cs

示例11: ReturnImage

 protected void ReturnImage(HttpResponse response, string path, string requestedETag)
 {
     response.Clear();
     var responseETag = LookupEtagFromInput(path);
     if (requestedETag == responseETag)
     {
         response.StatusCode = 304;
         response.StatusDescription = "Not Modified";
         response.AppendHeader("Content-Length", "0");
         response.AppendHeader("Connection", "Close");
         response.End();
     }
     
     response.ContentType = GetContentType(path);
     response.TransmitFile(path);
     response.AppendHeader("Connection", "Keep-Alive");
     // set cache info
     response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
     response.Cache.VaryByHeaders["If-Modified-Since"] = true;
     response.Cache.VaryByHeaders["If-None-Match"] = true;
     response.Cache.SetLastModified(File.GetLastWriteTime(path));
     response.Cache.SetETag(responseETag);
     response.End();
 }
开发者ID:rosenkolev,项目名称:ASP.NET-Responsive-Images,代码行数:24,代码来源:ImageContentHandler.cs

示例12: sendResponseAsJson

 private void sendResponseAsJson(HttpResponse response, string responseString)
 {
     response.Clear();
     response.BufferOutput = true;
     response.StatusCode = 200; // HttpStatusCode.OK;
     response.Write(responseString);
     response.ContentType = "application/json; charset=utf-8";
     response.End();
 }
开发者ID:kum63304,项目名称:SmartHouse,代码行数:9,代码来源:ArduinoHttpHandler.cs

示例13: FailResponse

 private static Task FailResponse(HttpResponse response, string message, int statusCode = 400)
 {
     response.StatusCode = statusCode;
     return response.End(message);
 }
开发者ID:FabianGosebrink,项目名称:ASPNET-Core-Angular2-SignalR-Typescript,代码行数:5,代码来源:PersistentConnection.cs

示例14: OutputClientSireSelectionSheetsToPDF

    private static void OutputClientSireSelectionSheetsToPDF(LocalReport localReport, string fileName, bool landscape,
                                                             bool legal, HttpResponse response)
    {
        const string reportType = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension;

        // The DeviceInfo settings should be changed based on the reportType
        //      http://msdn2.microsoft.com/en-us/library/ms155397.aspx

        string deviceInfo =
            "<DeviceInfo>" +
            "  <OutputFormat>PDF</OutputFormat>" +
            "  <PageWidth>" + (landscape ? (legal ? "14" : "11") : "8.5") + "in</PageWidth>" +
            "  <PageHeight>" + (landscape ? "8.5" : (legal ? "14" : "11")) + "in</PageHeight>" +
            "  <MarginTop>0.3in</MarginTop>" +
            "  <MarginLeft>1.25in</MarginLeft>" +
            "  <MarginRight>0.25in</MarginRight>" +
            "  <MarginBottom>0.3in</MarginBottom>" +
            "</DeviceInfo>";

        /*  other attributes for the DeviceInfo are
            StartPage - The first page of the report to render. A value of 0 indicates that all pages are rendered. The default value is 1.
            Columns - The number of columns to set for the report. This value overrides the report's original settings.
            ColumnSpacing - The column spacing to set for the report. This value overrides the report's original settings.
            EndPage - The last page of the report to render. The default value is the value for StartPage.
        */

        Warning[] warnings;
        string[] streams;

        //Render the report
        byte[] renderedBytes = localReport.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

        // Clear the response stream and write the bytes to the outputstream
        // Set content-disposition to "attachment" so that user is prompted to take an action
        // on the file (open or save)
        response.Clear();
        response.ContentType = mimeType;
        response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + fileNameExtension);
        response.BinaryWrite(renderedBytes);
        response.End();
    }
开发者ID:BeefboosterDevelopment,项目名称:Intranet,代码行数:51,代码来源:Report404.ascx.cs

示例15: ExportCSV

    public static int numFieldOfImportFile = 16; //number column of import file

    #endregion Fields

    #region Methods

    /// <summary>
    /// Export data to csv and response directly
    /// </summary>
    /// <param name="response">Current page response</param>
    /// <param name="fileName">export file name</param>
    /// <param name="listData">list data to export</param>
    public static void ExportCSV(HttpResponse response, string fileName, List<ImportExportFields> listData)
    {
        //prepare the output stream
        response.Clear();
        response.Buffer = true;
        // response.ContentType = "text/csv";
        response.ContentType = "application/octet-stream";//application/vnd.ms-excel";
        response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
        //response.ContentEncoding = Encoding.Unicode;
        response.ContentEncoding = System.Text.Encoding.UTF8;
        response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());

        response.Write(DataToCsvString(listData));

        response.Flush();
        response.End();
    }
开发者ID:nazrulcse,项目名称:pollinatror,代码行数:29,代码来源:ImportExportUltility.cs


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