ASP.NET MVC:MsCharts正在开发dev而不是生产

时间:2011-10-19 21:05:19

标签: asp.net asp.net-mvc iis web-config mschart

在部署我的生产环境时,我无法让MsCharts工作。

该应用程序是一个带有IIS 7.5的.NET 4 ASP.NET MVC 2站点。

当我在Visual Studio的开发服务器上运行时,一切正常但是当我尝试在实际网站上运行带有图表的页面时出现以下错误:

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'.

STACK TRACE:
at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext)
at System.Web.Mvc.ViewUserControl.RenderViewAndRestoreContentType(ViewPage containerPage, ViewContext viewContext)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.b__11()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.b__4()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.b__0()
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

BASE EXCEPTION:
No http handler was found for request type 'GET'

STACK TRACE:
at System.Web.HttpApplication.MapIntegratedHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig, Boolean convertNativeStaticFileModule)
at System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm)

在网上浏览了一堆我很难找到关于如何让MVC MsCharts在.NET 4中工作的明确答案,所以我每次都会找到一些零碎的东西,放在我的网上。配置。我不确定是否需要或者在正确的地方。应用程序的根web.config看起来像这样(删除多余的东西后):

<?xml version="1.0"?>

<configuration>

    <appSettings>
        <add key="ChartImageHandler" value="storage=file;URL=~/App_Data/MicrosoftChartControls/;timeout=20;" />
    </appSettings>

    <system.web>

        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </assemblies>
        </compilation>

        <httpHandlers>
            <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
        </httpHandlers>

    <system.web>
</configuration>

根视图文件夹中的web.config如下所示:

<?xml version="1.0"?>

<configuration>
    <system.web>
        <pages>
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            </controls>
        </pages>
    </system.web>

    <system.webServer>
        <handlers>
            <remove name="ChartImageHandler"/>
            <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        </handlers>
    </system.webServer>

</configuration>

在我的Global.asax.cs中我做到了:

protected void Application_Start()
{
    RouteTable.Routes.Ignore("{*pathInfo}", new { pathInfo = @"^.*(ChartImg.axd)$" });

    // ...
}

我呈现此图表的部分视图如下所示,Model.GraphChart控件:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

<h3><%: Model.ReportName %></h3>

<% chartPanel.Controls.Add(Model.Graph); %>

<asp:Panel ID="chartPanel" runat="server"></asp:Panel>

如果有任何影响,正在渲染它的视图位于区域中。

2 个答案:

答案 0 :(得分:0)

啊,发现了问题。我在Views文件夹中找到的web.config中放入了以下<handlers>部分:

<system.webServer>
    <handlers>
        <remove name="ChartImageHandler"/>
        <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </handlers>
</system.webServer>

将其移至应用程序根目录中的web.config使其正常工作。

答案 1 :(得分:0)

您是否在IIS中检查过是否为aspx页面配置了所需的映射?

进入IIS管理器 - &gt;默认网站 - &gt;处理程序映射