【问题标题】:asp.net MVC Serving Dynamic images not working on server (only local)asp.net MVC Serving Dynamic images not working on server (only local)
【发布时间】:2012-06-29 02:05:40
【问题描述】:

我正在尝试让 DevExpress 仪表控件在 MVC 中工作。实际教程在这里:http://www.devexpress.com/Support/Center/p/E2976.aspx。它通过 xml 文件创建设置并构建图像,然后将其存储在控制器的内存流中并推送到位于视图上的 img 标签。这个 img tags src attr 正在调用 Url.Action 来调用动作来渲染 Gauge。 Controller中的代码是这样的

[OutputCache(Duration = 1000, VaryByParam = "param")]
        public ActionResult RenderGauge(double param)
        {
            ASPxGaugeControl ctrl = new ASPxGaugeControl();
            param = param * 100;
            ctrl.RestoreLayoutFromXml(Server.MapPath("~/App_Data/gauge.xml"));
            (ctrl.Gauges["myGauge"] as CircularGauge).Scales["myScale"].Value = (float)param;

            MemoryStream stream = new MemoryStream();
            ctrl.ExportToImage(stream, ImageFormat.Jpeg);

            stream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(stream, "image/jpeg");
        }

视图如下所示:

<div style="background: 1px solid Blue; width; 240px;">
<%  double data = Model.ListData[0].Percentage; %>
                    <img src='<%: Url.Action("RenderGauge", "GetDashBoard", new RouteValueDictionary(new { param = data })) %>'
                        alt="Gauge showing data" id="gaugeImg1" />

    </div>

同样,这一切都在我的本地机器上运行,但在服务器上呕吐。 src attr 似乎渲染得很好:

<img src='/CINet/CorporateDashBoard/GetDashBoard/RenderGauge?param=0.7'
                        alt="Gauge showing data" id="gaugeImg1" />

我还想补充一点,这是 IIS 7、MVC 2,我尝试添加我在 Internet 上找到的特殊处理程序但没有成功:

<handlers>
      <add type="DevExpress.Web.ASPxUploadControl.ASPxUploadProgressHttpHandler, DevExpress.Web.v11.2, Version=11.2.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" name="ASPxUploadProgressHandler" preCondition="integratedMode" />
      <add name="PNG Images" path="*.png" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
 </handlers>

任何帮助将不胜感激!

【问题讨论】:

  • 页面渲染的完整路径是什么?您是否在任何 html 调试工具(firebug 等)中查看了 url,可能是图像路径存在问题。
  • 它到底在服务器上吐了什么?
  • 当您直接在浏览器的地址栏中键入操作的 url 时会发生什么:http://yourserver/CINet/CorporateDashBoard/GetDashBoard/RenderGauge?param=0.7?

标签: asp.net-mvc image dynamic asp.net-mvc-2 devexpress


【解决方案1】:

谢谢大家的提问,这很奇怪,因为它从来没有吐过,直接去那里会产生相同的结果,即显示“x”和替代文本但没有图像。原来是 DevExpress 的 Gauge dll 没有在服务器上本地复制。本来以为我会为此得到一个抱怨的例外,但是哦,好吧。希望这对其他人有帮助

【讨论】:

    猜你喜欢
    • 2017-01-31
    • 1970-01-01
    • 2022-12-28
    • 2022-12-19
    • 1970-01-01
    • 2021-10-22
    • 2013-01-26
    • 2017-04-08
    • 2019-01-01
    相关资源
    最近更新 更多