本文整理汇总了C#中System.Web.HttpResponse.End方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.End方法的具体用法?C# HttpResponse.End怎么用?C# HttpResponse.End使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.End方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResponseNoRight
/// <summary>NoRight
/// </summary>
/// <param name="request"></param>
/// <param name="respond"></param>
public static void ResponseNoRight(HttpRequest request, HttpResponse respond)
{
if (IsAjax(request))
{
respond.Write(ResponseCodeEntity.NoRight);
respond.End();
}
else
{
respond.Redirect(ResponseCodeEntity.NoRightURL);//需要改成非调转形式
respond.End();
}
}
示例2: ResponseNotfound
/// <summary>URL404
/// </summary>
/// <param name="request"></param>
/// <param name="respond"></param>
public static void ResponseNotfound(HttpRequest request, HttpResponse respond)
{
if (IsAjax(request))
{
respond.Write(ResponseCodeEntity.CODE404);
respond.End();
}
else
{
respond.Redirect(ResponseCodeEntity.ULR404);
respond.End();
}
}
示例3: Real
private void Real(HttpResponse response, HttpRequest request)
{
if (File.Exists(request.PhysicalPath))
{
FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
response.Clear();
response.AddHeader("Content-Disposition", "filename=" + file.Name);
response.AddHeader("Content-Length", file.Length.ToString());
string fileExtension = file.Extension.ToLower();
switch (fileExtension)
{
case ".mp3":
response.ContentType = "audio/mpeg3";
break;
case ".mpeg":
response.ContentType = "video/mpeg";
break;
case ".jpg":
response.ContentType = "image/jpeg";
break;
case ".bmp":
response.ContentType = "image/bmp";
break;
case ".gif":
response.ContentType = "image/gif";
break;
case ".doc":
response.ContentType = "application/msword";
break;
case ".css":
response.ContentType = "text/css";
break;
case ".html":
response.ContentType = "text/html";
break;
case ".htm":
response.ContentType = "text/html";
break;
case ".swf":
response.ContentType = "application/x-shockwave-flash";
break;
case ".exe":
response.ContentType = "application/octet-stream";
break;
case ".inf":
response.ContentType = "application/x-texinfo";
break;
default:
response.ContentType = "application/octet-stream";
break;
}
response.WriteFile(file.FullName);
response.End();
}
else
{
response.Write("File Not Exists");
}
}
示例4: Real
private void Real(HttpResponse response, HttpRequest request)
{
if (File.Exists(request.PhysicalPath))
{
FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
response.Clear();
response.AddHeader("Content-Disposition", "filename=" + file.Name);
response.AddHeader("Content-Length", file.Length.ToString());
string fileExtension = file.Extension.ToLower();
switch (fileExtension)
{
case ".jpg":
response.ContentType = "image/jpeg";
break;
case ".gif":
response.ContentType = "image/gif";
break;
case ".png":
response.ContentType = "image/png";
break;
default:
response.ContentType = "application/octet-stream";
break;
}
response.WriteFile(file.FullName);
response.End();
}
else
{
response.Write("File Not Exists");
}
}
示例5: WriteJsonResponse
public static void WriteJsonResponse(HttpResponse response, object model)
{
var serializer = new JavaScriptSerializer();
string json = serializer.Serialize(model);
response.Write(json);
response.End();
}
示例6: ExportToExcelFile
/// <summary>
/// Exporta la información a Excel.
/// </summary>
/// <param name="response">HttpResponse actual.</param>
/// <param name="data">Datos a exportar.</param>
/// <param name="nombreArchivo">Nombre del archivo Excel</param>
public static void ExportToExcelFile(HttpResponse response, DataView data, string nombreArchivo)
{
var dg = new DataGrid { DataSource = data };
dg.DataBind();
response.Clear();
response.Buffer = true;
//application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
response.AddHeader("Content-Disposition", "filename=" + nombreArchivo);
response.ContentType = "application/vnd.ms-excel";
response.Charset = "UTF-8";
response.ContentEncoding = System.Text.Encoding.Default;
var stringWriter = new StringWriter();
var htmlWriter = new HtmlTextWriter(stringWriter);
dg.RenderControl(htmlWriter);
response.Write(stringWriter.ToString());
//resp.Flush();
try
{
response.End();
}
catch (Exception ex)
{
ISException.RegisterExcepcion(ex);
throw ex;
}
}
示例7: SendPosterToBrowser
public static void SendPosterToBrowser( PosterBuilder.Builder pb, HttpResponse resp, string posterFilename, PosterBuilder.ImgFormat.SupportedTypes outputFormat)
{
string filename = BuildFilename(posterFilename, outputFormat);
resp.Clear();
// Ensure caching is off naturally
resp.CacheControl = "no-cache";
resp.ContentType = PosterBuilder.ImgFormat.ToMimeType(outputFormat);
resp.AddHeader("Content-Disposition", "attachment;filename=" + filename);
// Call our image with our amendments and have it save to the response so we can send it back
Bitmap bmp = pb.Render();
// Have the Poster build our new image and save the result to the outgoing response
// ... have to do all this with MemoryStreams as PNG doesn't like being saved directly to HttpResponse.OutputStream
// ... may as well do the same for all image types and be consistent
using (Bitmap bitmap = pb.Render()) {
using (MemoryStream ms = new MemoryStream()) {
ImageFormat outFmt = PosterBuilder.ImgFormat.ToImageFormat(outputFormat);
bmp.Save(ms, outFmt);
ms.WriteTo(resp.OutputStream);
} // using ms
} // using pb
// And of course, clear up after ourselves
pb.Dispose();
resp.End();
}
示例8: ExportToExcel
public void ExportToExcel(DataTable dataTable, HttpResponse response)
{
// Create a dummy GridView
GridView GridView1 = new GridView();
GridView1.AllowPaging = false;
GridView1.DataSource = dataTable;
GridView1.DataBind();
response.Clear();
response.Buffer = true;
response.AddHeader("content-disposition", "attachment;filename=DataTable.xls");
response.Charset = "";
response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
for (int i = 0; (i
<= (GridView1.Rows.Count - 1)); i++)
{
// Apply text style to each Row
GridView1.Rows[i].Attributes.Add("class", "textmode");
}
GridView1.RenderControl(hw);
// style to format numbers to string
string style = "<style> .textmode{mso-number-format:\\@;}</style>";
response.Write(style);
response.Output.Write(sw.ToString());
response.Flush();
response.End();
}
示例9: ExportToCSV
public void ExportToCSV(DataTable dataTable, HttpResponse response)
{
response.Clear();
response.Buffer = true;
response.AddHeader("content-disposition",
"attachment;filename=DataTable.csv");
response.Charset = "";
response.ContentType = "application/text";
StringBuilder sb = new StringBuilder();
for (int k = 0; k < dataTable.Columns.Count; k++)
{
//add separator
sb.Append(dataTable.Columns[k].ColumnName + ',');
}
//append new line
sb.Append("\r\n");
for (int i = 0; i < dataTable.Rows.Count; i++)
{
for (int k = 0; k < dataTable.Columns.Count; k++)
{
//add separator
sb.Append(dataTable.Rows[i][k].ToString().Replace(",", ";") + ',');
}
//append new line
sb.Append("\r\n");
}
response.Output.Write(sb.ToString());
response.Flush();
response.End();
}
示例10: Do302Redirect
public static void Do302Redirect(HttpResponse response, string targetURL)
{
response.StatusCode = 0x12e;
response.StatusDescription = "302 Moved Permanently";
response.RedirectLocation = targetURL;
response.End();
}
示例11: DataTableToExcel
/// <summary>
/// Datatable数据填充如excel
/// </summary>
/// <param name="filename">excel文件名</param>
/// <param name="dt"> 数据源</param>
/// <param name="Response"> response响应</param>
/// <param name="headerStr"> 表头标题</param>
public static void DataTableToExcel(string filename, DataTable dt, string sheetname, HttpResponse Response, string headerStr)
{
MemoryStream ms = StreamData(dt, sheetname, headerStr) as MemoryStream; //as MemoryStream as用作转换,此处可以省略
try
{
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename + ".xls"));
Response.AddHeader("content-length", ms.Length.ToString());
Byte[] data = ms.ToArray(); //文件写入采用二进制流的方式。所以此处要转换为字节数组
Response.BinaryWrite(data);
}
catch
{
Response.Clear();
Response.ClearHeaders();
Response.Write("<script language=javascript>alert( '导出Excel错误'); </script>");
}
Response.Flush();
Response.Close();
Response.End();
ms = null;
}
示例12: SendNotFoundResponse
private static void SendNotFoundResponse(string message, HttpResponse httpResponse)
{
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
httpResponse.ContentType = "text/plain";
httpResponse.Write(message);
httpResponse.End(); // This terminates the HTTP processing pipeline
}
示例13: SendFileNotFound
private static void SendFileNotFound(HttpResponse response)
{
response.ClearHeaders();
response.StatusCode = 404; //not found
response.StatusDescription = "Not Found";
response.End();
}
示例14: RedirectPermanent
static void RedirectPermanent(HttpResponse response, string destination)
{
response.Clear();
response.Status = "301 Moved Permanently";
response.AddHeader("Location", destination);
response.Flush();
response.End();
}
示例15: CloseIt
public static void CloseIt(HttpResponse response)
{
response.Clear();
response.Write("<script type=\"text/javascript\">");
response.Write("window.close();");
response.Write("</script>");
response.End();
}