Popular Posts
Generate subversion diff report using python bash: svn --diff-cmd "python" --extensions "diff_to_html.py" diff -r 596:671 diff_to_html.py import sys import diff... JSRequest, Get parameters from querystring with javascript in SharePoint Provides method to parse query string, filename, and pathname from URL // Initialize first JSRequest.EnsureSetup(); // Get the current fil... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Output a file like url via routing
Prepare a binary output action for file output
[RoutePrefix("images")]
public class ImageController : Controller
{
    // GET: ~/images/profile.png
    // GET: ~/images/1873429732.jpg
    [HttpGet]
    [Route("{name}.{ext}")]
    public ActionResult ReadImage(string name, string ext)
    {
        if (System.IO.File.Exists(Server.MapPath(string.Format("~/uploads/{0}.{1}", name, ext))))
        {
            byte[] data = System.IO.File.ReadAllBytes(Server.MapPath(string.Format("~/uploads/{0}.{1}", name, ext)));
            string contentType = MimeMapping.GetMimeMapping(System.IO.Path.GetFileName(string.Format("{0}.{1}", name, ext)));
            return File(data, contentType);
        }
        else
        {
            return new HttpStatusCodeResult(404);
        }
    }
}

Then try test it, but respone 404 not found.




Add runAllManagedModulesForAllRequests="true" on modules section.


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  ...
  <system.webServer>
    ...
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>
    </modules>
  </system.webServer>
  ...
</configuration>

Then try it again, image rendered success.