对于GEOMAP Asp.net谷歌图表SSL处理(Asp.net Google Charts SS

2019-10-21 02:24发布

我试图使用SSL网站,查看谷歌的图表。

谷歌图表不支持SSL的,所以如果我们使用标准的图表,我们得到警告消息。

我的计划是创建在安全的网站,将会从谷歌的内容和服务给用户正在浏览的页面co9ntained一个ASHX处理程序。

使用VS 2008 SP1以及包含的Web服务器,我的想法完全适用于Firefox和IE 8和9(预览版),我能看到我的地理分布图显示我的网页上也应该如此。 但我的问题是,当我使用发布我的处理程序,以产生在Firefox的地理分布图的作品,但不是IE浏览器(每一个版本),以IIS7的页面。

有没有错误的任何地方或任何日志文件,但是当我用右键单击IE浏览器中应显示在地图的区域,我看到在上下文菜单中的消息说“不加载的影片”

下面是我的处理程序和aspx页面的代码。

我在我的web.config禁用压缩。

即使在IE浏览器,我打我的所有的破发点,当我使用IE9 Developer工具,网页被正确地与所有正确的代码,网址和引用生成。

如果您有任何更好的方法来做到这一点或如何,我可以解决我的问题,我将不胜感激。

谢谢

伊恩

传输(ASHX)

  public void ProcessRequest(HttpContext context)
    {
        String url = "http://charts.apis.google.com/jsapi";

        string query = context.Request.QueryString.ToString();
        if (!string.IsNullOrEmpty(query))
        {
            url = query;
        }

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(HttpUtility.UrlDecode(url)));

        request.UserAgent = context.Request.UserAgent;
        WebResponse response = request.GetResponse();

        string PageContent = string.Empty;
        StreamReader Reader;

        Stream webStream = response.GetResponseStream();

        string contentType = response.ContentType;

        context.Response.BufferOutput = true;
        context.Response.ContentType = contentType;
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        context.Response.Cache.SetNoServerCaching();
        context.Response.Cache.SetMaxAge(System.TimeSpan.Zero);

                string newUrl = IanLearning.Properties.Settings.Default.HandlerURL; //"https://localhost:444/googlesecurecharts.ashx?";

        if (response.ContentType.Contains("javascript"))
        {
            Reader = new StreamReader(webStream);
            PageContent = Reader.ReadToEnd();

            PageContent = PageContent.Replace("http://", newUrl + "http://");
            PageContent = PageContent.Replace("charts.apis.google.com", newUrl + "charts.apis.google.com");
            PageContent = PageContent.Replace(newUrl + "http://maps.google.com/maps/api/", "http://maps.google.com/maps/api/");

            context.Response.Write(PageContent);
        }
        else
        {
            {
                byte[] bytes = ReadFully(webStream);
                context.Response.BinaryWrite(bytes);
            }
        }

        context.Response.Flush();
        response.Close();
        webStream.Close();
        context.Response.End();
        context.ApplicationInstance.CompleteRequest();
    }

ASPX页面

<%@ Page Title="" Language="C#" MasterPageFile="~/Site2.Master" AutoEventWireup="true"
    CodeBehind="googlechart.aspx.cs" Inherits="IanLearning.googlechart" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<script type='text/javascript' src='~/googlesecurecharts.ashx?'></script>
<script type='text/javascript'>
    google.load('visualization', '1', { 'packages': ['geomap'] });
    google.setOnLoadCallback(drawMap);

    var geomap;

    function drawMap() {
        var data = new google.visualization.DataTable();
        data.addRows(6);
        data.addColumn('string', 'City');
        data.addColumn('number', 'Sales');
        data.setValue(0, 0, 'ZA');
        data.setValue(0, 1, 200);
        data.setValue(1, 0, 'US');
        data.setValue(1, 1, 300);
        data.setValue(2, 0, 'BR');
        data.setValue(2, 1, 400);
        data.setValue(3, 0, 'CN');
        data.setValue(3, 1, 500);
        data.setValue(4, 0, 'IN');
        data.setValue(4, 1, 600);
        data.setValue(5, 0, 'ZW');
        data.setValue(5, 1, 700);

        var options = {};
        options['region'] = 'world';
        options['dataMode'] = 'regions';
        options['showZoomOut'] = false;

        var container = document.getElementById('map_canvas');
        geomap = new google.visualization.GeoMap(container);

        google.visualization.events.addListener(
        geomap, 'regionClick', function(e) {
            drillDown(e['region']);
        });

        geomap.draw(data, options);
    };

    function drillDown(regionData) {
      alert(regionData);
    }
</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id='map_canvas'>
    </div>
</asp:Content>
文章来源: Asp.net Google Charts SSL handler for GeoMap