public static void ResourceNotFound(this HttpResponse response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            response.ClearContent();
            response.AddHeader("Content-Length", 0.ToString());
            response.StatusCode = (int) HttpStatusCode.NotFound;
        }
Exemple #2
0
        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();
        }
 /// <summary>
 /// 输出Json文本到客户端
 /// </summary>
 /// <param name="Response"></param>
 /// <param name="json"></param>
 public static void WriteJson(this HttpResponseBase Response, IJson json)
 {
     Response.ContentType = "application/json";
     Response.ClearContent();
     Response.BinaryWrite(Encoding.UTF8.GetBytes(json.ToString()));
     Response.Flush();
 }
 /// <summary>
 /// 输出纯文本到客户端
 /// </summary>
 /// <param name="Response"></param>
 /// <param name="text"></param>
 public static void WriteText(this HttpResponseBase Response, string text)
 {
     Response.ContentType = "text/plain";
     Response.ClearContent();
     Response.BinaryWrite(Encoding.UTF8.GetBytes(text));
     Response.Flush();
 }
 /// <summary>
 /// 输出Jsonp文本到客户端
 /// </summary>
 /// <param name="Response"></param>
 /// <param name="callBack">客户端的js回调方法</param>
 /// <param name="json">json参数</param>
 public static void WriteJsonp(this HttpResponseBase Response, string callBack, IJson json)
 {
     Response.ContentType = "application/x-javascript";
     Response.ClearContent();
     Response.BinaryWrite(Encoding.UTF8.GetBytes(string.Format("{0}({1});", callBack, json.ToString())));
     Response.Flush();
 }
 public static void CreatePDF(this HttpResponse response, byte[] pdf, string filename)
 {
     response.ClearContent();
     response.ClearHeaders();
     response.ContentType = "application/pdf";
     //Response.ContentType = @"application/octet-stream";
     response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".pdf");
     response.OutputStream.Write(pdf, 0, pdf.Length);
     response.BufferOutput = true;
     response.BinaryWrite(pdf);
     response.Flush();
     response.End();
 }