本文介绍了iFrame在localhost中显示PDF,但不在网页中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前尝试过这个问题,但没有得到任何真正的答案,所以也许我没有正确解释。让我这样试试吧。我的程序搜索在线存储在Web文件夹中的(PDF)文档。然后它应该在网页上的iFrame中显示它。我尝试了这两种方式,既可以作为HTML5网页iFrame,也可以作为谷歌文档。 Google Docs的代码如下所示,但两者都产生相同的结果,即空白页(没有错误),但两个完美运行的工作作为Visual Studio 10中的localHost页运行:



I tried this question earlier but did not get any real answers, so perhaps I am not explaining it correctly. Let me try it this way. My program searches for a (PDF) document that is stored in a web folder online. It is then supposed to display it in an iFrame on a web-page. I have tried this two ways, both as an HTML5 web-page iFrame and also as a google docs. Code for Google Docs is shown below, but both produce the same result which is a blank page (no errors) but BOTH work perfectly run run as a localHost page from Visual Studio 10:

//Page 1
//Create a new SQL Connection Object
        SqlConnection Conn = new SqlConnection(CONNSTR);

        try
        {
            string Sql = "SELECT [NAME],[LOCATION] FROM TTW_MISC WHERE [NAME] = @NAME ORDER BY [NAME] ASC ";

            //Set Command Object Headers
            SqlCommand Comm = new SqlCommand(Sql, Conn);
            //For an Sql Command
            Comm.CommandType = CommandType.Text;
            //For a Stored Procedure
            //Comm.CommandType = CommandType.StoredProcedure;

            //Comm Paramemters
            Comm.Parameters.Clear();
            Comm.Parameters.AddWithValue("@NAME", "TTW_Story.pdf");

            //Create a Dataset
            SqlDataAdapter da = new SqlDataAdapter(Comm);
            DataSet ds = new DataSet();
            da.Fill(ds);

            location3 = ds.Tables[0].Rows[0]["LOCATION"].ToString();
            CEO1 = ds.Tables[0].Rows[0]["NAME"].ToString();
        }
        catch (Exception ex)  //Catch Errors
        {
            Console.WriteLine("Error : " + ex.Message);
        }

        Session["Document"] = location3 + CEO1;
        Response.Redirect("TTW_Doc_Reader.aspx", false);

//Page 2 (iFrame)
        //Using iFrame with Google Docs
        if (Session["Document"].ToString() != string.Empty)
        {
            string document = Session["Document"].ToString();
            string pdfPage = "http://docs.google.com/gview?url=" + document + "&embedded=true";
            pdiFrame.Attributes.Add("src", pdfPage);
        }
        else
        {
            ClientScriptManager script = Page.ClientScript;
            if (!script.IsClientScriptBlockRegistered(this.GetType(), "Alert"))
            {
                script.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Sorry, this document cannot be found. ')", true);
                return;
            }
        }





因为它在VS 10中运行时效果很好,我假设那个由于它是同一页面,因此它正在在线正确传递,并且加载页面源中的检查似乎验证了,但我得到的只是一个空白页面。所有我能想到的是某种安全问题,不是让页面从服务器上下来,但我不知道如何检查这一点,或者即使我走在正确的轨道上。为什么它可以在桌面上运行?我现在已经超过一周了。多年来,我从Code Project获得了很多帮助,并且始终解决了这个问题。我提前感谢您的帮助!请帮助。再次感谢,Pat。



我尝试过:



我已尝试过Google文档和HTML 5 iFrame直接代码。我已经验证了源文档并且它已存在。我检查了代码的准确性,它在Visual Studio 10中运行时完全解析。我检查了网页源,以确保它正在寻找一个真实的页面,并且页面格式代码是正确的(它必须是因为它从localhost运行时,以两种格式都可以找到并完美显示。我尝试了3种不同的浏览器(Firefox,Chrome,Explorer)。我通过搜索任何类似的问题摧毁了互联网,我发现没有任何东西与我的问题相符,考虑到我从VS locahost完成后已经有效。



Since it works perfectly when it is run in VS 10, I "ASSUME" that the it is being passed correctly online since it is the same page, and a check in the loaded page source appears to verify that, but all I get is a blank page. All I can think of is some kind of security issue that is not letting the page come down from the server, but I do not know how to check this, or even if I am on the right track. Why does it work from the desktop? I'm more than a week on this now. I have received great assistance from Code Project over the years and have always resolved the problem. I thank you in advance for your assistance! PLEASE PLEASE HELP. Thanks again, Pat.

What I have tried:

I have tried both Google docs and HTML 5 iFrame direct code. I have verified the source document and it's existence. I have checked the code for accuracy and it resolves perfectly when run in Visual Studio 10. I have checked the web page source to make sure it is looking for a real page and that the page format code is correct (which it must be since it is found and displayed perfectly in both formats when run from the localhost). I have tried 3 different browsers (Firefox, Chrome, Explorer). I have decimated the internet with searches for any similar issue and I have found nothing that matches my issue, considering mine already works when done from the VS locahost.

推荐答案


这篇关于iFrame在localhost中显示PDF,但不在网页中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:11
查看更多