File://c:/<path> does not display contents

T

TLM

I am trying to build a web application that will contain
links to files on a users local computer. I am assuming
that the files will be in a known location and can display
in a browser window.

I have my ASP.NET application building links along the
lines of

file://c:/<path to file>

When I use the link in IE 6.0's address bar, I am able to
see the file as expected. If I use the link on an ordinary
HTML page, I am also able to use the link and receive the
file as expected.

I can refer to pages via file://localhost if (and only if)
they are located in my inetpub/wwwroot directory of a
computer with IIS or PWS (but since I cannot assume that
my users have that, it does not really help). I have
found that once I have called a plain HTML file in this
way, if it has links in the file://c:/<file path> format,
they work normally.

However, when I use the link from within an ASPX page, the
page does not change. I have seen occasionally (but not
always) a bit of a JavaScript message in the status bar
that appears to be some validation firing that simply
redirects me back where I started -- effectively doing
nothing.

So: I know that the failure to display the file is not a
browser issue per se since I can use the File: url in both
the address bar and a plain HTML page. I have a suspicion
that there is some default validation code that prevents
this sort of URL from firing from VS 2003-built ASPX.

I am even able to find the path in the output HTML file
and past that into the IE address bar to navigate to the
file -- I just cannot navigate to it from within the ASPX
page.

I have not found any solid references to this sort of
thing on the net or in my hardcopy books.

I have tried setting validateRequests = "false" without
effect. Same with commenting out references to
vs_defaultClientScript.

I have also tried this from other computers (Win2k, XP
Home, XP Pro), and I have tried using invalid file: URLs
as well (these don't even return a 404 error). Attepting
to 'open in new window' has variously returned the bit of
JavaScript in the address bar and done nothing.

Unfortunately, one or another of the things I have tried
is now preventing the JavaScript from appearing, but as I
recal, it was calling a page_validate method of some sort.

When I put the path as the SRC of an iFrame on an ASPX
file, the frame shows nothing: viewing the source of the
frame shows only a pair of empty <HTML></HTML> tags.

Links using the HTTP:// path work normally; those using
file:// do not. The net effect is that 'nothing' apparent
to the user seems to be happening.

This looks like a security 'feature' albiet an
inconvenient one for me.

Does anyone have any suggestions on how to reference files
on a local computer drive from within an ASPX file?
 
T

TLM

Aditional information:

1) an ASPX page can be built by other IDEs or by hand
(e.g. Dreamweaver, etc.) and the file://c:/<path name>
will work as expected

2) if the ASPX page is imported into a VS project and run
from within the project, the file://c:/<path name> will
not work (links will fail, page will not be displayed in
an iFrame, etc.). This occurs even if the ULL is hard-
coded rather than generated.

3) if the page is converted to a plain HTML page that is
included as a part of a VS project, the file://c:/<path
name> will not work (links will fail, page will not be
displayed in an iFrame, etc.)

4) if the resulting HTML source from either the plain HTML
or ASPX from the VS project is saved as an independent
HTML file, the file://c:/<path name> will work as expected

=======SAMPLE HTML=================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<html>
<head>
<title>test page</title>
</head>
<body>
<table width="100%" border="0" cellspacing="2"
cellpadding="2" ID="Table1">
<tr>
<td>header</td>
</tr>
<tr>
<td>
<iframe
id="lessonArea" SRC="file://c:/test/test.htm"></iframe>
</td>
</tr>
</table>


</body>
</html>

===================================

So: the problem seems to be an effect of the VS project:
there is something about the ASPX generated by VS that
prevents file://C:/<path name> from firing normally.

This has been seen with both IIS 6 and the PWS that can be
run from an XP Pro computer.
 
T

TLM

Additional Information:

Oddly, when the URL is hardcoded in an iFrame (see sample
below), the contents will display in the VS IDE, but not
when the page is actually run.

===== SAMPLE CODE =========
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="Testing.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<table width="100%" border="0"
cellspacing="2" cellpadding="2">
<TBODY>
<tr>

<td>header</td>
</tr>
<tr>
<td>

<iframe id="lessonArea"
SRC="file://c:/test/test.htm" runat="server"></iframe>

<asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="file:///C:\test\test.htm">HyperLink</asp:Hyper
Link>
</td>
</tr>
</form>
</TBODY></TABLE>
</body>
</HTML>



===========================

note that a 404 eror is expected if the user does not have
a file at c:\test\test.htm, but what is occuring is that
nothing is displayed and the link just plain does not
appear to fire.
 
P

Patrice

Check the HTML code for the HyperLink client side to see if it is correct.

I doubt you'll have a 404 error for a file that doesn't exist as this is an
HTTP error code and you don't use HTTP when accessing the local file...

Also double check those pesky /// and avoid / and \ confusion...

Good luck

Patrice
 
T

TLM

RETRACTION:

This behavior does not appear when running the pages on a
Windows 2000 Pro computer; but does appear on XP SP2
computers.
 
P

Patrice

Found also :

Note Internet Explorer 6 Service Pack 1 (SP1) no longer allows browsing a
local machine from the Internet zone. For instance, if an Internet site
contains a link to a local file, Internet Explorer 6 SP1 displays a blank
page when a user clicks on the link. Previous versions of Internet Explorer
followed the link to the local file.

Could it be related to this ?
 
G

Guest

THank you, Patrice.

This does seem to be somewhat related. I have been continuing to explore
this, and I am finding that the problem occurs on the XP machines in my
network, but not on a Win2K machine.

On one of the XP (SP2) machines, I have installed Firefox (to check if it is
simply an IE thing) and found the same problem.

When I ran a test page through FireFox on the Win2K machine that allows me
to use the file:// path as expected in IE (6.0.2800.1106, SP1), the page pae
failed in Firefox in the same way that it did on the XP SP2 machine.

So, I think that you are correct that this is some sort of security thing. I
am just not clear on precisely what it is or if there is a work around.

It does seem odd that the file:// code will run as expected outside of an
ASPX file (e.g. in an HTML file built from the output of the ASPX and run
outside of the webserver itself).

If the security is attempting to prevent use of the file://c:/<path name>
urls, why only with pages generated in Visual Studio?
 
G

Guest

Additional Info:

I have since created an ASPX project in DreamWeaver MX to test this.

With IE
On the XP SP2 computer, the problem continues to occur, but does not on the
Win2K computer.

With Firefox
The problem occurs on both the XP and Win2K computers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top