Link to home
Start Free TrialLog in
Avatar of domj
domj

asked on

window.navigate command getting "Access Denied" error

For some reason I cant get the window to navigate to the new address. The address is a local path to a file in the temp directory. Code is below. The function main simply uses a recordset to create a new html page in the users TEMP directory and the window.navigate is meant to just open this page but no go! I'm sure it is something simple but, any ideas?

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script language=vbscript>
'**Start Encode**
Set fso=CreateObject("Scripting.FileSystemObject")
Set dbCon = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
pUBLIC STRdbcON
Public fsofile
Set wshell=CreateObject("WScript.Shell")
Public PCName
Public Curdir

pcname=Wshell.ExpandEnvironmentStrings("%USERNAME%")
curDir=WShell.ExpandEnvironmentStrings("%Temp%")

Function sesbyDate()
strDBCon="Provider=SQLOLEDB.1;User ID=dbUser;Initial Catalog=Templates_Synch;Data Source=foneent"
dbCon.Errors.Clear
dbCon.Open strDBCon

Main()
window.navigate CurDir & "\" & pcname & "Report.html"

End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dom
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of domj
domj

ASKER

nope, same message "permission denied"

Dom
So you're using something like:

file://c:/WINDOWS/Temp/
Avatar of domj

ASKER

The file is being created in the users temp folder. Earlier in the script the curDir=WShell.ExpandEnvironmentStrings("%Temp%") line gets the current users temp fodler using the %TEMP% variable. Then I create a new text file in this directory and write html to it, dependent on the results of the recordset that is opened in the main() function. The file is created properly and i can manually navigate to it but I want the browser to jump to it, once it is finished creating it so that it is seamless for the end user.

Dom
Try this:

window.navigate "file://" & CurDir & "\" & pcname & "Report.html"
Avatar of domj

ASKER

nope, same again. For some reason its not letting me change the access in code. weird. its got to have to do with security because when i run it locally (ie, when the page is not published) it runs fine but once it is run from a web server it fails.

Dom
Oh, you're running it from a webserver. Yes, it is the security. I don't believe you can get past that... Otherwise, a person could just change files on your computer without you knowing
Avatar of domj

ASKER

yeh but it is doing the file stuff fine. the file is creating and everything without any problems. to facilitate this the end user needs to add the intranet site to trusted sites and heavily reduce the activex security for these sites but it works fine once these changes have been done. The stuff that should be really secure (ie. actually changing files and reading environment variables) is working fine once the appropriate changes have been made. The bit that doesnt work is simply navigating to view a html file on the local machine. all it is is trying to change the address of the current window which I thought would be the easiest thing in the world to do. its just the equivalent of clicking on a link but it doesnt work. (you can tell how little web development i have done!)

dom
Creating the file is totally different from accessing it. I'm not immensely familiar with ASP/VBScript. Possibly there's a way, but it's beyond my knowledge.
Avatar of domj

ASKER

Thanks anyway Zyloch. appreciate your help. anybody else? Have increased points value to 500.

Dom
Just try something like this -- using javascript
<input type=button value=click Onclick=window.open("../../yourfile")>
Avatar of domj

ASKER

sgayatri, thanks for the input but if i was going to do that i may as well just post a link. i can find ways around it but i am just intrigued as to why i am having this problem. for example, i can use the wshell.run command to shell the path of the file and open in a new browser. therefore i could shell any command including hostile script. i can't understand why it would block me then from doing something as simple as navigating the current window to a new page.

dom
Hey there,

This might sound silly, but do you close the file? It could be that the file is still open for writing or for append and then you try and navigate to it while it's still in use.

Cheers,
TM
IE had some issues with cross domain security and they solved it by NOT ALLOWING it at all. This means that if you want to use a frame to load a diffrent domain from the current one it just tells you Access Denied..

The window.open option could solve your problem but if not .. try using a shell script to execute a new instance of IE with the file location of the current users file. Also remember that the shell command has to have local admin rights to do this or you would be back to the same problem...

Here is a alternet solution..

Instead of writing the file to the users PC.. let them download the thing... this way they can access it at there own will... To get that right send the browser a mall-formed header so it doesn't display the HTML file but wants to download it.. the rest is then up to the user..

Another idea is to write the file to a common file server and then redirect the user to that file server.

Cross doamin access is a bit of a mission...

Good Luck
Adesso21
domj,
I am not very sure about why you get that error. May be due to the reasons explained by Adesso21.
I could not understand much of what he is trying to tell.
I happened to see ur question in VB section and out of curiosity came here and posted my opinion.
That's all.
Adesso21,
If it is 'cross domain issue' , then enabling the security option 'Access data sources across domains'
in internet options , should solve the problem... Am I right?
Avatar of domj

ASKER

Hi all,

Here I was thinking that it would be an easy fix! thunder_moose, yes the file is closed before I try to access it but I have been caught out with this before (as I am suremost people have)!

Adesso21, firstly, the page is published and accessed all on a common domain to which I am a Domain Admin and therefore I can't see where there should be a permissions problem. The window.open command doesnt work for me either (same issue, "Access Denied"). The shell command does work fine and I could use this method but then the user can't use the back button to get back to the first page and also it leaves the old page up and if I use a window.close to try and ditch it it comes up with the "Are you sure you want to close it" prompt. I am not sure what the suggestion regarding the downloading thing is. The reason that I am using a temp folder on the local PC is that the page is to display a report for a FTP synchronisation tool that I have written. The logs get pulled up into a SQL 2000 db and then I wanted a nice easily distributable reporting option to allow our help desk to access custom reports. The page allows the user to click on a number of links to run reports that it then prompts for user input and uses this info and embedded vb code to query the SQL db. It creates a recordset and then goes through each record, writing HTML containing this information into a new text document and then displays this document (or is meant to at least). The reason that this is done client side is because I dont have the skills to look at ASP or any server side solution.

All that said, the entire thing works great and apart from some early problems with security and the activex objects (like the fso and the environment variable access) and this one hiccup, the file gets created fine and you can manually go to the page and it displays like a charm. Its just that for some reason, IE locks down all access from code to anything that will get the current page to navigate away. I could redirect to a common file server but I dont know if that would even work. It might be worth a try and if someone was able to say "oh yeah, you cant do that because..." then i could look at another option but it just seems like the most trivial thing to be able to do from a webpage.

Thanks all for you input... Am still interested to hear if anyone has any further insight or common experience with a similar issue.

Dom
sgayatri

I am not sure that changing the setting in IE will do anything.. Last I read somthing about Microsoft wanting you to create some kind of Trusted certificate between the two domains and then implementing some funny browser security check .. I gave up..

As for the real question DomJ.. You are going to have to get your hand dirty with some kind of server side scripting.. The way you are going now is almost not possible. I get what you are trying to do, and let me tell you.. it's a breeze in server side scripting..

I like using PHP but ASP should be fine.. this is not rocket sience ... reporting.. but the way that you are trying to do it.. could be..

I hope you get a solution..

Regards

Adesso21
A suggestion: Why don't you create the file on the server and then link to that file vis HTTP ?
The main page would hve to be a ASP ot CGI page
Excuse me, but shouldn't it be:
window.navigate CurDir & "/" & pcname & "/" & "Report.html"
or
window.navigate CurDir & "\" & pcname & "\" & "Report.html"

rather than:
window.navigate CurDir & "\" & pcname & "Report.html"

What I would suggest you to do first is print out (either in MsgBox, or better just to dynamically write it somewhere in the doc) the value of [CurDir & "\" & pcname & "Report.html"] and then just copy it and paste it to the address field in the browser.
also, put this output here, maybe we can see something in it....

Good luck
Zvika
I'm quite sure that all you're missing is the extra "\" between pcname & "Report.html"...

Lemme know if that it...

Avatar of domj

ASKER

No, that syntax is correct. The file path is "C:\Documents and settings\DominicJ\Local Settings\Temp\DominicJReport.html". I could copy and paste the value. Seems like a very poor way of coding it and open to problems. What if the user copies something in the meanwhile? How do I give focus to the address bar?

Dom
domj

I didn't mean you to use this as workaround. just as a debugging way to see that the path is built ok and that the file is actually there.
anyway, it looks wierd.
one more test for you. write a hard-coded file path, to a file you KNOW is already there. I mean, make a test. put a "test.html" file in c:\, and write the path "c:\test.html" hard coded in your function. see if that also fails.

supply the feedback and we'll see how we take i forward...

Zvika
Avatar of domj

ASKER

Oh, OK. Yeh the path works fine. I have tried replacing the path with another. For some reason IE is blocking any attempt that I make to access the window address object.

Dom
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
well, domj sisn't say if it helped him, so I can't say "Points to me".
I think that if no comment to him, it will be fair to split them among those who gave some effort.... what say you?