IIS7, web.config to allow only static file handler in directory /uploads of website

Add the following to a web.config file in the folder containing the files you wish to be served only as static content: <configuration> <system.webServer> <handlers> <clear /> <add name=”StaticFile” path=”*” verb=”*” modules=”StaticFileModule,DefaultDocumentModule,DirectoryListingModule” resourceType=”Either” requireAccess=”Read” /> </handlers> <staticContent> <mimeMap fileExtension=”.*” mimeType=”application/octet-stream” /> </staticContent> </system.webServer> </configuration>

Retrieve image from database in asp.net

Create a generic http handler as follows using System; using System.Configuration; using System.Web; using System.IO; using System.Data; using System.Data.SqlClient; public class ShowImage : IHttpHandler { public void ProcessRequest(HttpContext context) { Int32 empno; if (context.Request.QueryString[“id”] != null) empno = Convert.ToInt32(context.Request.QueryString[“id”]); else throw new ArgumentException(“No parameter specified”); context.Response.ContentType = “image/jpeg”; Stream strm = ShowEmpImage(empno); byte[] buffer = … Read more

tech