MVC3 Handler.ashx

时间:2012-05-19 07:23:31

标签: asp.net-mvc-3 handler

您好我从ActionResult调用Handler.ashx

 ViewBag.IMG = "Handler.ashx?img=" + imagetest +

,如果ActionResult是Index,它可以正常工作,

http://localhost:11111/ImageHandler.ashx?img=image

但是,如果它是任何其他名称,它不会调用处理程序!

http://localhost:11111/ActionReult(name)/ImageHandler.ashx?img=image

它在网址中添加了ActionResult名称。

任何想法,提前谢谢。

1 个答案:

答案 0 :(得分:0)

然后我不明白假,.ashx反而可以使用控制器返回FileContentResult或FileResult到File或FileStreamResult到File。

样品

public FileContentResult Index()
{
    var Resim = new WebClient().DownloadData("https://dosyalar.blob.core.windows.net/dosya/kartalisveris.gif");
    return new FileContentResult(Resim, "image/png"); //* With {.FileDownloadName = "Höbölö"}
}

或者

public FileResult Index()
{
    FileInfo fi = new FileInfo(Server.MapPath("~/Content/imgs/fillo_kargo.png"));
    return File(fi.OpenRead, "image/png"); //or .FileDownloadName("Eheheh :)") Return File(fi.OpenRead, "audio/mpeg","Media File")
}

以便通过变量public

  

FileResult索引(字符串picPath)

     

FileInfo fi = new FileInfo(Server.MapPath(“〜/ Content / imgs /”+ picPath +   “));

网址:文件/索引/ fillo_kargo.png

相关问题