Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you were to do this using ASP.NET 3.5 Sp1 WebForms you would have to create a seperate ImageHTTPHandler that implements IHttpHandler to handle the response. Essentially all you would have to do is put the code that is currently in the GetHttpHandler method into your ImageHttpHandler's ProcessRequest method. I also would move the GetContentType method into the ImageHTTPHandler class. Also add a variable to hold the name of the file. </p> <p>Then your ImageRouteHanlder class looks like:</p> <pre><code>public class ImageRouteHandler:IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { string filename = requestContext.RouteData.Values["filename"] as string; return new ImageHttpHandler(filename); } } </code></pre> <p>and you ImageHttpHandler class would look like:</p> <pre><code> public class ImageHttpHandler:IHttpHandler { private string _fileName; public ImageHttpHandler(string filename) { _fileName = filename; } #region IHttpHandler Members public bool IsReusable { get { throw new NotImplementedException(); } } public void ProcessRequest(HttpContext context) { if (string.IsNullOrEmpty(_fileName)) { context.Response.Clear(); context.Response.StatusCode = 404; context.Response.End(); } else { context.Response.Clear(); context.Response.ContentType = GetContentType(context.Request.Url.ToString()); // find physical path to image here. string filepath = context.Server.MapPath("~/images/" + _fileName); context.Response.WriteFile(filepath); context.Response.End(); } } private static string GetContentType(String path) { switch (Path.GetExtension(path)) { case ".bmp": return "Image/bmp"; case ".gif": return "Image/gif"; case ".jpg": return "Image/jpeg"; case ".png": return "Image/png"; default: break; } return ""; } #endregion } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload