Click to See Complete Forum and Search --> : What if the URL variable doesn't exist ?


fuseboxx
08-29-2005, 12:35 PM
Hi - I have a simple script that I use to open a file in a frameset based on the variable passed in the URL. What it does is take the URL= variable and set that as the main frameset. The only problem is if the page doesn't exist I get a 404 error.

I'd like to enhance it a bit more and if the file doesn't exist I would also like to set the URL Variable to my main.htm page.


I know in JavaScript you check for the existence of the file, but I'm not sure what the.asp code is to validate this ---- Would appreciate any guidance - the script is below

********************************************************

<%@LANGUAGE="VBSCRIPT"%>

<% If Request.QueryString("URL") = "" Then URL = "welcome.htm" Else URL = Request.QueryString("URL") End If %>

<html>
<head>
<title></title>
</head>
<frameset framespacing="0" border="false" frameborder="0" rows="85,*">
<frame name="top" scrolling="no" src="top.htm" marginwidth="0" marginheight="0" target="main">
<frame name="main" src="<%= URL %>">

<noframes>
<body>
text Here
</body>
</noframes>
</frameset>
</html>

buntine
08-29-2005, 07:26 PM
Use the FileSystem object. It has a function called FileExists.

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(URL) Then
'| Code block
Else
'| Alternate code block
End If

Regards.

fuseboxx
08-31-2005, 08:15 AM
Hey thanks - Don't really know where I'm going wron here as everything looks to be set. I'm still getting a server 500 error.

Any assistance would be appreciated.

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



<%@LANGUAGE="VBSCRIPT"%>


<%
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(URL) Then
URL = <%= URL %>
Else
URL = "whatsnew.htm"
End If
%>

<html>
<head>
<title>test page </title>
</head>
<frameset framespacing="0" border="false" frameborder="0" rows="85,*">
<frame name="top" scrolling="no" src="top.htm"

marginwidth="0" marginheight="0" target="main">
<frame name="main" src="<%= URL %>">

<noframes>
<body>
text Here
</body>
</noframes>
</frameset>
</html>

buntine
08-31-2005, 07:57 PM
Turn off friendly HTTP errors.

From IE: Tools > Internet Options > Advanced Tab > Uncheck "Show friendly HTTP error messages".

What is the error now?