本文整理匯總了C#中System.Web.HttpResponseBase.ClearContent方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpResponseBase.ClearContent方法的具體用法?C# HttpResponseBase.ClearContent怎麽用?C# HttpResponseBase.ClearContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.ClearContent方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CheckForAuthorizationFailure
/// <summary>
/// Checks for authorization failure and if result of ajax call overrides asp.net redirect to return a 401.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="response">The response.</param>
/// <param name="context">The context.</param>
internal void CheckForAuthorizationFailure(HttpRequestBase request, HttpResponseBase response, HttpContextBase context)
{
if (!request.IsAjaxRequest() || !true.Equals(context.Items["RequestWasNotAuthorized"])) return;
response.StatusCode = 401;
response.ClearContent();
var content = new {title = HttpContext.GetGlobalResourceObject("Session", "Title.SessionHasExpired"), content = HttpContext.GetGlobalResourceObject("Session", "Messsage.SessionHasExpired")};
var serializer = new JavaScriptSerializer();
response.Write(serializer.Serialize(content));
}
示例2: CheckForAuthFailure
internal void CheckForAuthFailure(HttpRequestBase request, HttpResponseBase response, HttpContextBase context)
{
//NOTE: This will change *all* 302's for AJAX requests to 401s. That could cause problems, but it will
// work for now.
if (response.StatusCode == 302 && request.IsAjaxRequest())
{
response.StatusCode = 401;
response.ClearContent();
}
}
示例3: ResponseImg
private void ResponseImg(HttpResponseBase response, string pic)
{
try
{
string FilePath = AppDomain.CurrentDomain.BaseDirectory;
FilePath = Path.Combine(FilePath, "App_Data\\" + imgpath);
string FileFullPath = Path.Combine(FilePath, pic);
string FileExt = Path.GetExtension(FileFullPath);
if (U.ExtValid(FileExt))
{
if (File.Exists(FileFullPath))
{
FileExt = FileExt.ToLower();
Image Img = Image.FromFile(FileFullPath);
ImageFormat format = ImageFormat.Jpeg;
switch (FileExt)
{
case ".gif":
format = ImageFormat.Gif;
break;
case ".jpg":
format = ImageFormat.Jpeg;
break;
case ".png":
format = ImageFormat.Png;
break;
default:
break;
}
response.ClearContent();
response.ContentType = "image/bmp";
Img.Save(response.OutputStream, format);
Img.Dispose();
response.Flush();
}
else
{
response.Write("file DO NOT Exists");
}
}
else
{
response.Write("file DO NOT Allow");
}
}
catch (Exception ex)
{
log.Warn(ex.Message);
log.Warn("imgpath:{0},imgname:{1}", imgpath, imgname);
}
}
示例4: SetHttpResponse
private void SetHttpResponse(HttpResponseBase httpResponse, string fileNameWithoutExtension, ExcelPackage package)
{
httpResponse.ClearContent();
httpResponse.Buffer = true;
//Write it back to the client
httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
httpResponse.AddHeader("content-disposition", string.Format("attachment; filename={0}.xlsx", fileNameWithoutExtension));
httpResponse.BinaryWrite(package.GetAsByteArray());
httpResponse.Flush();
httpResponse.End();
}
示例5: 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();
}
示例6: DumpXls
public static void DumpXls(HttpResponseBase response, DataTable table, string fileName)
{
var grid = new GridView();
grid.DataSource = table;
grid.DataBind();
response.ClearContent();
response.Buffer = true;
response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName));
response.ContentType = "application/ms-excel";
response.Charset = "";
var sw = new StringWriter();
var htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
response.Output.Write(sw.ToString());
response.Flush();
response.End();
}
示例7: CreateCheckCodeImage
private void CreateCheckCodeImage(string checkCode, HttpResponseBase response)
{
if (checkCode == null || checkCode.Trim() == String.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 16.5)), 35);
Graphics g = Graphics.FromImage(image);
try
{
//生成隨機生成器
Random random = new Random();
//清空圖片背景色
g.Clear(Color.White);
// Pen drawPen = new Pen(Color.Blue);
// 添加多種顏色 hooyes
Color[] colors = { Color.Blue,Color.Silver,Color.SlateGray,Color.Turquoise,Color.Violet,Color.Turquoise,Color.Tomato,Color.Thistle,Color.Teal,Color.SteelBlue };
//畫圖片的背景噪音線
for (int i = 0; i < 9; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
Pen drawPen2 = new Pen(colors[i]);
g.DrawLine(drawPen2, x1, y1, x2, y2);
}
// drawPen.Dispose(); Tahoma
Font font = new System.Drawing.Font("Arial", 13, (System.Drawing.FontStyle.Bold));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.Gray, 1.2f, true);
g.DrawString(checkCode, font, brush, 2, 1);
// g.DrawString("J", font, brush, 1, 115);
font.Dispose();
brush.Dispose();
//畫圖片的前景噪音點
for (int i = 0; i < 20; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(0x8b, 0x8b, 0x8b));
}
//畫圖片的邊框線
Pen borderPen = new Pen(Color.Transparent);
g.DrawRectangle(borderPen, 0, 0, image.Width - 1, image.Height - 1);
borderPen.Dispose();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] buffer = ms.ToArray();
ms.Dispose();
response.ClearContent();
response.ContentType = "image/bmp";
response.BinaryWrite(buffer);
}
finally
{
g.Dispose();
image.Dispose();
}
}
示例8: WriteToHttpResponse
/// <summary>
/// Exports the chart to the specified HttpResponse object. This method
/// is preferred over WriteToStream() because it handles clearing the
/// output stream and setting the HTTP reponse headers.
/// </summary>
/// <param name="httpResponse"></param>
public void WriteToHttpResponse(HttpResponseBase httpResponse)
{
httpResponse.ClearContent();
httpResponse.ClearHeaders();
httpResponse.ContentType = this.ContentType;
httpResponse.AddHeader("Content-Disposition", this.ContentDisposition);
WriteToStream(httpResponse.OutputStream);
}
示例9: GetCode
/// <summary>
/// 生成位圖,輸出到響應流
/// </summary>
/// <param name="Response"></param>
/// <param name="Code"></param>
public static void GetCode(HttpResponseBase Response, out string Code)
{
Code = string.Empty;
Bitmap bit = GetCode(out Code);
////清除該頁輸出緩存,設置該頁無緩存
//Response.Buffer = true;
//Response.ExpiresAbsolute = DateTime.Now.AddMilliseconds(0);
//Response.Expires = 0;
//Response.CacheControl = "no-cache";
//Response.AppendHeader("Pragma", "No-Cache");
Response.ClearContent();
bit.Save(Response.OutputStream, ImageFormat.Png);
Response.ContentType = "image/png";
//釋放資源
bit.Dispose();
}
示例10: GenerarPdf7
private static void GenerarPdf7(DataTable dt, string titulo, string nombreDoc, EmpresaDTO objEmpresa, DateTime? FechaFin, HttpResponseBase Response)
{
GridView gv = new GridView();
gv.DataSource = dt;
gv.AllowPaging = false;
gv.DataBind();
if (dt.Rows.Count > 0)
{
PintarCabeceraTabla(gv);
//PintarIntercaladoCategorias(gv);
AddSuperHeader(gv, titulo + " - Empresa:" + objEmpresa.Nombre);
//Cabecera principal
AddWhiteHeader(gv, 1, "");
AddWhiteHeader(gv, 2, "FECHA LIMITE: " + FechaFin.GetValueOrDefault().ToShortDateString());
//PintarCategorias(gv);
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + nombreDoc + "_" + objEmpresa.Nombre + "_" + DateTime.Now.ToString("dd-MM-yyyy") + ".xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
htw.Close();
sw.Close();
}
}
示例11: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
response.BufferOutput = false;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Cookies.Clear();
response.ContentType = ContentType;
response.ContentEncoding = Encoding.Default;
response.AddHeader("Content-Type", ContentType);
response.AddHeader("Content-Disposition",
String.Format("attachment; filename={0}",
this.FileDownloadName));
byte[] buffer = new byte[4096];
using (ZipOutputStream zipOutputStream =
new ZipOutputStream(response.OutputStream))
{
foreach (string fileName in FilesToZip)
{
int folderOffset = fileName.LastIndexOf('\\');
Stream fs = System.IO.File.OpenRead(fileName); // or any suitable inputstream
string entryName = fileName.Substring(folderOffset);
ZipEntry entry = new ZipEntry(ZipEntry.CleanName(entryName));
entry.Size = fs.Length;
// Setting the Size provides WinXP built-in extractor compatibility,
// but if not available, you can set zipOutputStream.UseZip64 = UseZip64.Off instead.
zipOutputStream.PutNextEntry(entry);
//zipOutputStream.SetLevel(3); // 0-9 for compression level
//zipOutputStream.Password(); // security
int count = fs.Read(buffer, 0, buffer.Length);
while (count > 0)
{
zipOutputStream.Write(buffer, 0, count);
count = fs.Read(buffer, 0, buffer.Length);
if (!response.IsClientConnected)
{
break;
}
response.Flush();
}
fs.Close();
}
zipOutputStream.Finish();
}
//response.OutputStream.Flush();
response.End();
}
示例12: ExportToExcel
private void ExportToExcel(string exportContent, HttpResponseBase response)
{
response.Clear();
response.ClearContent();
response.AddHeader("content-disposition", "attachment;filename=" + fileName);
response.Charset = "";
response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
response.Write(exportContent);
response.End();
}