Microsoft Technologies based on the .NET software framework. Miscellaneous topics that do not fit into specific categories.
Please use an iframe instead of the Literal control and set the url of HTTP handler to the src attribute of iframe.
See sample below:
HTTP Handler Handler4.ashx
using System;
using System.Web;
namespace WebForms1
{
public class Handler4 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetExpires(DateTime.Now.ToUniversalTime());
context.Response.Cache.SetMaxAge(new TimeSpan(0, 0, 0, 0));
context.Response.ContentType = "application/pdf";
// byte array is obtained from the file in Files holder (not from DB)
string filename = "JBL4312G.pdf";
string path = context.Server.MapPath("~/Files") + "\\" + filename;
byte[] data = System.IO.File.ReadAllBytes(path);
context.Response.BinaryWrite(data);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm33.aspx.cs" Inherits="WebForms1.WebForm33" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<h1>pdf in iframe</h1>
<iframe src="Handler4.ashx" width="500" height="500"></iframe>
</form>
</body>
</html>
result