【问题标题】:Display Google Doc in IFRAME in ASP.Net Application在 ASP.Net 应用程序的 IFRAME 中显示 Google Doc
【发布时间】:2013-06-25 06:56:56
【问题描述】:

我正在开发一个 .net 应用程序,该应用程序允许用户将 google doc 链接附加到应用程序并从应用程序本身查看/编辑它们。我使用 iframe 将谷歌文档嵌入到我的应用程序中。

由于应用程序中嵌入的谷歌文档应该离线发生,我使用来自谷歌 API 的访问令牌来获取 URL 并显示。我在这方面有显示问题。

我已经完成了与获取根据 Google API 文档“离线”打开 google 文档所需的访问令牌相关的所有工作。根据 google api 开发人员文档,在打开 google doc url 时,我需要将访问令牌作为查询参数或作为请求标头(“授权”标头)传递。

我尝试使用 Authorization 标头并使用 HttpWebRequest 对象打开 google doc url,但我没有正确打开 doc 页面..

aspx 文件中的代码

htmlBuilder.AppendFormat("<iframe src='ShowFiles.ashx?url={0}' id='myFrame' name='myFrame' width='100%' height='100%' marginheight='0' frameborder='0'></iframe>", urlLink);

通用处理程序 (ShowFiles.ashx) 文件中的代码

// get the UrlLink from the Query Parameter (url) 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(urlLink);
myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like 
                               Gecko) Chrome/27.0.1453.116    Safari/537.36"; 
myHttpWebRequest.Headers.Add("Authorization", "Bearer " + accessToken); 
string pageContent = string.Empty; 
HttpWebResponse HttpWResp = (HttpWebResponse)myHttpWebRequest.GetResponse();
if (HttpWResp != null)
{
    StreamReader sr = new StreamReader(HttpWResp.GetResponseStream());
    pageContent = sr.ReadToEnd();
}
context.Response.ContentType = HttpWResp.ContentType;
context.Response.Write(pageContent);

浏览器确实打开了谷歌文档,但是一旦打开它就一直说“正在尝试连接到谷歌”,并且一直弹出警告说“服务器没有响应”

所以我尝试使用访问令牌作为 URL LINK 的查询参数,但这似乎根本不起作用。 例如: urlLink = "http://google.docs.com/myDoc/myFile?access_token=fsdfsfsq4334234_df

并将此 url 设置为 iframe src

<iframe src=urlLink>

这根本不起作用......

我知道,如果在同一个浏览器中我登录到我的 google 帐户,我有这个 google 驱动器文档(在另一个选项卡中),然后在我的 web 应用程序中没有这个访问令牌,我的 iframe 完美地加载了 google 文档,只需给出文档网址,如

http://google.docs.com/myDoc/myFile">

我尝试使用 jQuery ajax 从客户端打开 url,然后 google 文档被打开,但变为只读。

var jqXHR = $.ajax({
            async: true,
            url: url,
            type: 'GET',
            xhr: function () {
                var xhr = new window.XMLHttpRequest();
                return xhr;
            },
            beforeSend: function (xhr) {
                if (xhr != null)
                    xhr.setRequestHeader("Authorization", "Bearer " + token);
            }
        });

        jqXHR.done(function (data, textStatus, xhr) {
            $("#myFrame").contents().find("html").html(xhr.responseText);
        });

谁能帮助我在我的网络应用程序的 IFRAME 中正确显示此 google 文档(在编辑模式下)

【问题讨论】:

    标签: iframe google-docs google-docs-api google-oauth


    【解决方案1】:

    我认为 google docs 使用 HTTPS,这意味着您不能在自己的网站上嵌入 HTTPS 网站。我之前尝试使用具有 HTTPS 或 ssl 证书的 iframe 嵌入网站,所以我得出了这个结论。

    【讨论】:

    • 如果是这种情况,那么我在一个选项卡中登录了 gmail 帐户,并在另一个选项卡中打开我的网络应用程序,我可以将 iframe src 设置为 google docs,它会正确显示并且我能够编辑文档
    猜你喜欢
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 2013-09-24
    • 2015-07-19
    相关资源
    最近更新 更多