2
Uncaught TypeError: Cannot read property 'docViewer' of undefined
Problem reported by Delwyn Pinto - 9/30/2020 at 1:44 AM
Resolved
My project is on Vb.Net with Framework version 4.
I have added Document Ultimate is a User Control following the steps mentioned here :
https://docs.gleamtech.com/documentultimate/html/adding-references-to-documentultimate-assemblies.htm
https://docs.gleamtech.com/documentultimate/html/using-documentultimate-in-an-asp-net-webforms-project.htm

While the UI is loading, the document does not open and throws the error messages in the image attached.



Code is as follows :

<%@ Register TagPrefix="GleamTech" Namespace="GleamTech.DocumentUltimate" Assembly="GleamTech.DocumentUltimate" %>
<%@ Register TagPrefix="GleamTech" Namespace="GleamTech.DocumentUltimate.AspNet.WebForms" Assembly="GleamTech.DocumentUltimate" %>

<script type="text/javascript" src="<%=siteURL%>Javascript/swfobject.js"></script>

<div id="<%=popUpFlashWrapperID%>">

<GleamTech:DocumentViewerControl ID="documentViewer" runat="server"
Width="800"
Height="600"
Document="<absolute path to .doc file>" />
</div>



Have I missed anything ? 

9 Replies

Reply to Thread
0
Cem Alacayir Replied
Employee Post
As you can see from the error message, this is a cross domain issue:


More information on this issue:

Chrome starting with version 76 treats cookies as SameSite=Lax by default if no SameSite attribute is specified.

And ASP.NET without below these updates (it's about the version on your deployment server, not VS development environment), does not emit the SameSite cookie header for the None value (SameSite=None):
For .NET Framework 4.6 to 4.7.2, install KB 4524421
For .NET Framework 4.8, install KB 4531182

  • Before the patch a value of Nonemeant:
    • Do not emit the attribute at all.
  • After the patch:
    • A value of None means "Emit the attribute with a value of None".
    • The default SameSite value for forms authentication and session state cookies was changed from None to Lax.
After these updates, you can use this setting in Web.config and SameSite=None cookie header will be sent:

<system.web>
        <httpCookies sameSite="None" />
        <sessionState cookieSameSite="None" /> 
</system.web>    
For more details:

0
Delwyn Pinto Replied

Hi,

The exact same code worked in a fresh blank project, with the exact same tech stack. Which leads me to believe the cause of this error is something else entirely.

Also, our project is a legacy project. Upgrading the .NET framework from version 4.0 to 4.8 will be tedious which we would like to avoid.

Is there any other way to get around this error ?

0
Delwyn Pinto Replied
Hi. Still waiting for a response. We have client deliverables that are pending on this.
Could it be possible to look into this on priority ?
0
Delwyn Pinto Replied
Hi, we have purchased an Enterprise License for Document Ultimate but still facing these errors.
Any ideas on how to resolve this ?
0
Cem Alacayir Replied
Employee Post
> Upgrading the .NET framework from version 4.0 to 4.8 will be tedious which we would like to avoid 

Did you read my post carefully?

> And ASP.NET without below these updates (it's about the version on your deployment server, not VS development environment) 

>The exact same code worked in a fresh blank project, with the exact same tech stack.

Well then in your main project there is something that is overtaking request URLs like resource.ashx because your browser complains it's from a different domain? Are you using UrlRewrite rules in your Web.config?
0
Delwyn Pinto Replied
Hi Cem,

There was a URLRewrite rule in the project, but the same error is thrown even after removing it. Nor are there any Handlers that could be causing this. From debugging the code of Document Ultimate via Chrome Dev Tools, I can see that the instance of docViewer is lost during its execution.

Is there anything else we can look into regarding this ?
0
Cem Alacayir Replied
Employee Post
If you are using an iframe and cross-domain url, see the announcement here:
0
Delwyn Pinto Replied
We do not use an iframe, as you can see in the code posted in the question.
0
Cem Alacayir Replied
Employee Post Marked As Resolution
There is also an internal iframe in DocumentViewer.

Open Network tab in your browser console and examine where request for /resource.ashx/605466187810000000/webviewer/Reader.html is being redirected (you can search for reader.html), for example if it's redirected to myDomain.com/resource.ashx/605466187810000000/webviewer/Reader.html then of course it will not work because it becomes cross domain (because your main page is still e.g. for localhost domain).

> I can see that the instance of docViewer is lost during its execution. 

It's not lost but because the iframe becomes cross-domain due to your Rewrite rules, the browser does not allow access of docViewer variable anymore.

Here is a rule that stops rules for GleamTech handlers (this is for Microsoft's UrlRewrite module but the idea is same):


<rewrite>

    <rules>

        <rule name="Stop Rewriting for GleamTech Handlers" stopProcessing="true">

            <match url="(resource|filemanager|fileuploader|documentviewer)\.ashx" />

            <action type="None" />

        </rule>

        .

        .

        .

    </rules>

</rewrite>


Add this rule to the top of the rules and when the request is .ashx, it will stop processing your other rules so that the .ashx request passes through and works.




Reply to Thread