CustomPdfHandler not working with search result widget
Hello Team,
I just created CustomPdfHandler to restrict users to see pdf of my application. It works fine with content block widget means when i give link of pdf in content block widget it is not allowing all users to see pdf but when i search pdf from search widget and click on search result links, handler is not working and all users are able to see pdf files.!! Can any one help please ?
Regards.
My custom handler is in App-Code/CustomPdfHandler.cs file something like this:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//namespace Login_role.App_Code
//
public class CustomPdfHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
/// <summary>
/// You will need to configure this handler in the web.config file of your
/// web and register it with IIS before being able to use it. For more information
/// see the following link: go.microsoft.com/
/// </summary>
public void ProcessRequest(HttpContext context)
if (context.Session["UserName"] == null)
//if (!context.User.Identity.IsAuthenticated)
context.Response.Redirect("/Login Role/Login.aspx?ReturnUrl=" + HttpContext.Current.Request.RawUrl.ToString());
context.Response.StatusCode = 401;
return;
var url = context.Request.CurrentExecutionFilePath;
if (string.IsNullOrEmpty(url)) return;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("filename=0", url));
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.WriteFile(url);
HttpContext.Current.Response.End();
public bool IsReusable
get return false;
//
And In web.config file/<httpHandlers>
<add verb="*" path="*.pdf" type="CustomPdfHandler, App_Code" validate="false" />
and
In <handlers>
<add name="PdfRestrict" path="*.pdf" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
I did above codes to handle Custom handlers.