Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.redirect doesn't work and Open file opens a file in browser

Status
Not open for further replies.

Devenfadia

Programmer
Feb 3, 2003
6
US
Hi,

I am using response.redirect to redirect, which works fine on one of our servers but doesn't work on another server. I tried lots of solutions but nothing helped. Second Problem is open file which is opening a file or let user save the file on his/her desktop works fine on one server but another server it is trying to open a file in browser. and if the file is PDF document then it shows some garbage.

I will really appreciate your help.

By the way it's on windows 2000 server with IIS 5.0.

Here is the code:

<%

Dim filename, fileID, method, test, strDoc, temp, tempurl
filename = request.querystring(&quot;filename&quot;)
fileID = request.querystring(&quot;fileID&quot;)
strDoc = filename


Dim rsHistory, ls_sql, MySql
Set rsHistory = Server.CreateObject(&quot;ADODB.Recordset&quot;)
ls_sql = &quot;select * from CA_History &quot;



If Request.Form(&quot;R1&quot;) = &quot;Email&quot; then
Response.redirect(buildurl(&quot;SendAttachments.asp&quot;&&quot;&fileid=&quot; & cstr(fileID))

else
if Request.Form(&quot;R1&quot;) = &quot;Open&quot; then

method = &quot;Open&quot;
Dim Stream
Dim Contents
Dim FileExt
Const adTypeBinary = 1
If filename = &quot;&quot; Then
Response.Write &quot;Filename not specified.&quot;
Response.End
End If
' Make sure they are not requesting your
' code
FileExt = Mid(filename, InStrRev(filename, &quot;.&quot;) + 1)
Select Case UCase(FileExt)
Case &quot;ASP&quot;, &quot;ASA&quot;, &quot;ASPX&quot;, &quot;ASAX&quot;, &quot;MDB&quot;
Response.Write &quot;Protected file not allowed.&quot;
Response.End
End Select



' Download the file
Response.Clear
Response.ContentType = &quot;application/octet-stream&quot;
Response.AddHeader &quot;content-disposition&quot;, &quot;attachment; filename=&quot; & FileName
Set Stream = server.CreateObject(&quot;ADODB.Stream&quot;)
Stream.Type = adTypeBinary
Stream.Open
Stream.LoadFromFile Server.MapPath(&quot;\Email Data\CorrectiveAction\&quot; & FileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
' response.redirect(&quot;History.go(-1)&quot;)





Set Stream = Nothing
Response.Flush


else


Set File = CreateObject(&quot;Scripting.FileSystemObject&quot;)
ImagePath = &quot;Inetpub\&quot;

ImagePath = ImagePath & filename

MySql = &quot;Delete from FileAttachments where FileID = &quot; & fileID

If File.fileExists(ImagePath) Then
Session(&quot;db_con&quot;).Execute(MySql)
File.DeleteFile(ImagePath)
%>



<html>
<head>
<title>Action</title>
</head>
<body>



<table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;1&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;100%&quot; bgcolor=&quot;#993366&quot;><font color=&quot;#FFFFFF&quot; face=&quot;Arial&quot; size=&quot;2&quot;><b>Delete
Confirmation</b></font></td>
</tr>


<tr>
<td width=&quot;100%&quot; bgcolor=&quot;#C0C0C0&quot; valign=&quot;top&quot;>
<form name=&quot;form1&quot; method=&quot;POST&quot; action=&quot;<%=session(&quot;urladdr&quot;)%> &quot;>
<input type=&quot;hidden&quot; name=&quot;link&quot; value>
<input type=&quot;hidden&quot; name=&quot;linktab&quot; value>
<input type=&quot;hidden&quot; value name=&quot;ChangesFlag&quot;>


<table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;1&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;100%&quot; align=&quot;center&quot;>
<p align=&quot;left&quot;> File has been deleted.
</td>
</tr>
<tr>
<td width=&quot;100%&quot; align=&quot;center&quot;><input type=&quot;button&quot; value=&quot;Back&quot; name=&quot;Back&quot; onClick=&quot;func9()&quot;>
</td>
</tr>
</table>
</form>


</td>
</tr>

</table>




<%

Else
response.write(&quot;File doesn't exists.&quot;)
End if

End if



end if




%>
</body>

</html>


 
redirect I believe is only avail in the latest release. the server may be running on a older version
also when using a redirect commonly use adjust the buffer to avoid header errors
Response.Buffer = True
second question, look into setting the contentType of the page
eg: response.ContentType =&quot;application/pdf&quot;


_____________________________________________________________________
onpnt2.gif
[sub]
Hakuna matata!!
[/sub]
 
Hi OnPnt,

Regarding the Response.redirect, Actually it is working on other pages. I have other asp pages which are not having any kind of problems in response.redirect. Only this page is having problem in response.redirect.

And regarding the opening file, that is also working on one server and not working on the other server.

I will really appreciate your help.

Thank you,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top