Response.ContentType = "application/pdf"
Jeg har flyttet et gammelt Classic asp site fra en gammel Windows 2003 IIS server til en ny Windows 2012R2 IIS server, men får en fejl når der skal vises PDF filer.Kode:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Vis dokument</title>
</head>
<body>
<%
' prevent users to view the full url start
if request.querystring("id") <> "" then
session("id") = request.querystring("id")
response.redirect "/admin/showdocument.asp"
end if
' prevent users to view the full url end
' path to location of documents start
sti2 = "C:\inetpub\wwwSites\sql.intranet.hrh.dk\Dokumenter"
' path to location of documents end
' find document in document database start
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application( "SQLPath" )
sql = "SELECT * FROM [Dokumenter] WHERE ID = " & session("id")
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open sql, conn, 3,3
if rs.eof or rs.bof then
response.write "Dokument ikke fundet!"
else
Response.ContentType = "application/pdf"
Const adTypeBinary = 1
Dim strFilePath
strFilePath = sti2 & "\" & rs.Fields("fil")
response.write strFilePath
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
end if
rs.Close
set rs = nothing
conn.close
set conn = nothing
' find document in document database end
' set session to nothing start
session("id") = ""
' set session to nothing end
%>
</body>
</html>
Giver denne fejl:
Adobe Acrobat kommer med dette popup:
Filen starter ikke med '%PDF'. Local\EWH-3236-0
Det virker fint på 2003 IIS