If you need to have a dynamic url which is supposed to read files from specific location and return the feed to the browser, especially in the case where the end users are not supposed to have access to the files’ location, what can we do ?

ASP.net handler is the answer for this question

1- In Visual Studio, create a new ASP.net handler, imagesHandler.aspx

 

 

public void ProcessRequest(HttpContext context)
 {
 string imgName = context.Request.QueryString["n"];
 context.Response.ContentType = "image/png";
 string path = @"C:\Users\Public\Pictures\Sample Pictures\" + imgName;
 Image image = Image.FromFile(path);
 image.Save(context.Response.OutputStream, ImageFormat.Png);
}

Than, we can just use the url of the image control and point it to the handler

image.src = "images.ashx?n=penguin.jpg";

 

 

Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.